generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Easy, I Think

Previous Thread :: Next Thread 
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
24 Apr 2014 04:05 PM
How do I make it so that it gets players who have something in their PlayerGui, but forgets those who don't have it? Here's what I have, not working:

local players = game.Players:GetChildren()
for x = 1, #players do
if players[x] ~= it then
if players[x].PlayerGui.MapVote ~= nil then
players[x].PlayerGui.MapVote:Destroy()
elseif players[x].PlayerGui.MapVote == nil
then
--nothing
end
end
end
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
24 Apr 2014 04:11 PM
local players = game.Players:GetChildren()
for x = 1, #players do
end

^Dont use that. We have 'for' loops for tables.

local players = game.Players:GetChildren()
for i, v in pairs(players) do --Dont worry about 'i', its not used much. 'v' is basically 'x'
end
Report Abuse
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
26 Apr 2014 07:59 AM
Yeah, it's not working. I think I did something wrong:

local players = game.Players:GetChildren()
for i, v in pairs(players) do --Dont worry about 'i', its not used much. 'v' is basically 'x'
if players[v].PlayerGui.MapVote ~= nil then
players[v].PlayerGui.MapVote:Destroy()
elseif players[v].PlayerGui.MapVote == nil
then
--nothing
end
end
Report Abuse
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
26 Apr 2014 08:16 AM
Error says that on this line: if players[v].PlayerGui.MapVote ~= nil then "Attempt to index field '?' a nil value"
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
26 Apr 2014 08:22 AM
local tab = {"Hello World!","What a nice day!"}

for Index, Value in pairs(tab) do
print(Index,Value)
end


Run that to get the hang for these loops.
Report Abuse
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
26 Apr 2014 09:47 AM
Um. Ok?
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
26 Apr 2014 10:42 AM
if players[v].PlayerGui:FindFirstChild("MapVote") ~= nil then --Use :FindFirstChild() to check with nil
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
26 Apr 2014 10:46 AM
V IS NOT A NUMBER.
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
26 Apr 2014 10:52 AM
V is the value of the table, which in this case is the player, so just use v instead of players[v].

Here's my siggy... Done.
Report Abuse
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
26 Apr 2014 11:50 AM
I still don't get it. ;_;
Report Abuse
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
26 Apr 2014 12:10 PM
I think the only way for me to learn right now is for the full script to be posted? If this happens, please try to explain each part.
Report Abuse
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
26 Apr 2014 12:52 PM
Bump
Report Abuse
brinkokevin is not online. brinkokevin
Joined: 25 Jul 2012
Total Posts: 1673
26 Apr 2014 12:55 PM
you could try it like this also

for i,player in pairs(game.Players:GetChildren())do
if player then
if player.PlayerGui.MapVote then
player.PlayerGui.MapVote:Destroy()
else
--nothing
end
end
end
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
26 Apr 2014 01:12 PM
@OP Look at my script for something completely different.

parts = {game.Workspace.Part1, game.Workspace.Part2, game.Workspace.Part3} --Making a table, showing parts in Workspace. These are OBJECTS, NOT STRINGS.

for index,value in pairs(parts) do --Let's now loop through each value inside the table. Index is the position of the part in the table, value is the actual value in the position.
value.BrickColor = BrickColor.new("Bright red") --See how I don't use parts[value]. This turns the current value's BrickColor (in this case, one of the objects) in the script has looped through, to Bright Red.
end

Important facts to remember:
When using :GetChildren(), the table returns objects, not strings.
The first part of the for loop (index) is the position of the value the script has gone through in the loop.
The second part of the for loop (value) is the actual value that the script has gone through in the loop.
When trying to edit a value in a table, make sure you don't use parts[value] (could help in some cases, but not most of the time), just use value.

Here's my siggy... Done.
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
26 Apr 2014 01:15 PM
There's no reason to change his to a generic for loop, when that isn't even the problem here.

local players = game.Players:GetChildren()
for x = 1, #players do
if players[x] ~= it then
if players[x].PlayerGui:FindFirstChild("MapVote") ~= nil then
players[x].PlayerGui.MapVote:Destroy()
else
--nothing
end
end
end
Report Abuse
TexasTech717 is not online. TexasTech717
Joined: 24 Apr 2012
Total Posts: 1129
26 Apr 2014 02:37 PM
Thank you Josh, yours worked.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image