I'm puzzled. I want it to clone the GUI for each player, and whatnot. It works, but it clones it a bunch of times, and they dont count-down the whole time I put in. Can someone tell me why?
01 | print ( "enter" ) |
02 | function countdown(length) |
03 | for k,p in pairs (game.Players:GetPlayers()) do |
04 | local h = p.PlayerGui.TimerGui.Frame.TextLabel |
05 | for i = length, 1 ,- 1 do |
06 | h.Text = tostring (i) |
07 |
08 |
09 |
10 |
11 | end |
12 | end |
13 |
14 |
15 |
Three things I can see: msg:sub(), plr.Name == "LolPerson", and 'if' statements. When I do this kind of coding, I like to use the ':lower()' string so that the commands aren't Cap-Sensitive. Also, main I use the ':sub()'s for when its like '/kill player', I'd do the commands like this;
01 | if msg:lower():sub( 1 , 7 ) = = "/timer " then --Not cap-sensitive anymore |
02 | for i,v in pairs (game.Players:GetPlayers()) do --Gets all players |
03 | if v.Name:lower() = = msg:sub( 8 ) then --If name matches to the name that the speaker said then |
04 | if game.Lighting:FindFirstChild( "TimerGui" ) and v and v:FindFirstChild( "PlayerGui" ) then --I use this to see if the things exist, elseif we don't, the script may error :l |
05 | m = game.Lighting.TimerGui:Clone() --Clones the GUI |
06 | m.Parent = p.PlayerGui --Parents the Cloned gui into the Player's PlayerGui |
07 | end --The end for the 'if' statement that checks for the things |
08 | end --The end for the Player Name matching |
09 | end --The end for the 'for' loop (Get it?) |
10 | end --The end for the 'if msg:lower():sub() == "nil" then' statement |
Now, the name Checker, I'd probly do this;
1 | if msg.Name:lower() = = ( "PLAYER" ):lower() then --I do this just incase when the player joins, it'll lowercase all (Non-Cap-Sensitive stuff again), instead of erroring things that 'LOL' and 'lol' don't match because one is all lowercase and the other is all uppercase |
2 | end --The end for this 'if' statement |
Last but not least, the 'if' statements for the 'msg', I know this might be a bit harder, but its just my way without elseif's;
1 | if msg:lower() = = "nil" then --If the player chatted 'nil' then |
2 | print ( "nil is a keyword" ) --Will print 'nil is a keyword' |
3 | end --The end for the 'if' statement |
4 |
5 | if msg:lower():sub( 1 , 4 ) = = "nil/" --If command starts with 'nil/' then |
6 | print (msg:sub( 5 ).. " is nil" ) --Will print what the player said after 'nil/', and also do ' is nil' after what the player said |
7 | end |
I like to do that kind of thing for seperate commands, especialy Admin Commands. Now, I just noticed you were using a 'while true do end' loop for it, no no no you Silly Billy, try using the PlayerAdded event for it;
1 | game.Players.PlayerAdded:connect( function (plr) --Player has joined |
2 | if plr.Name:lower() = = ( "PLAYER" ):lower() then --Does plr.Name equal to PLAYER (Non-Cap-sensitive)?! :o |
3 | plr.Chatted:connect( function (msg) --He does! He gets to use Chatted commands! :D |
4 |
5 | -- Rest of coding |
6 |
7 | end ) --The end for the .Chatted event |
8 | end --The end for the 'if' statement |
9 | end ) --The end for the PlayerAdded event |
Also, your GUI may not be working due to the recent GUI update that which Roblox broke. :l I hope this helped bro!
You could try debouncing, or maybe having the script check to see if there are already GUI's in the player, and to remove them if they're already there. Multiple clones of something can cause problems with the script.