Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I get some help troubleshooting my script?

Asked by 10 years ago

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?

01print("enter")
02function 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
12end
13 
14 
15 
View all 57 lines...

2 answers

Log in to vote
2
Answered by 10 years ago

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;

01if msg:lower():sub(1,7) == "/timer " then --Not cap-sensitive anymore
02for i,v in pairs(game.Players:GetPlayers()) do --Gets all players
03if v.Name:lower() == msg:sub(8) then --If name matches to the name that the speaker said then
04if 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
05m=game.Lighting.TimerGui:Clone() --Clones the GUI
06m.Parent=p.PlayerGui --Parents the Cloned gui into the Player's PlayerGui
07end --The end for the 'if' statement that checks for the things
08end --The end for the Player Name matching
09end --The end for the 'for' loop (Get it?)
10end --The end for the 'if msg:lower():sub() == "nil" then' statement

Now, the name Checker, I'd probly do this;

1if 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
2end --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;

1if msg:lower() == "nil" then --If the player chatted 'nil' then
2print("nil is a keyword") --Will print 'nil is a keyword'
3end --The end for the 'if' statement
4 
5if msg:lower():sub(1,4) == "nil/" --If command starts with 'nil/' then
6print(msg:sub(5).." is nil") --Will print what the player said after 'nil/', and also do ' is nil' after what the player said
7end

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;

1game.Players.PlayerAdded:connect(function(plr) --Player has joined
2if plr.Name:lower() == ("PLAYER"):lower() then --Does plr.Name equal to PLAYER (Non-Cap-sensitive)?! :o
3plr.Chatted:connect(function(msg) --He does! He gets to use Chatted commands! :D
4 
5-- Rest of coding
6 
7end) --The end for the .Chatted event
8end --The end for the 'if' statement
9end) --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!

Ad
Log in to vote
-2
Answered by
Zerio920 285 Moderation Voter
10 years ago

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.

Answer this question