I maked a power-up in the game when you touch gives you speed, everything It's okay, but the text Isn't counting down when touched.
i make a script like this.
game.StarterGui.CounterSpeedGUI.TextLabel.Visible = false local counter = game.StarterGui.CounterSpeedGUI.TextLabel function OnTouch() script.Disabled = true wait() game.Players.LocalPlayer.PlayerGui.CounterSpeedGUI.TextLabel.Visible = true wait(1) counter.Text = "9" wait(1) counter.Text = "8" wait(1) counter.Text = "7" wait(1) counter.Text = "6" wait(1) counter.Text = "5" wait(1) counter.Text = "4" wait(1) counter.Text = "3" wait(1) counter.Text = "2" wait(1) counter.Text = "1" wait(1) game.Players.LocalPlayer.PlayerGui.CounterSpeedGUI.TextLabel.Visible = false counter.Text = "10" wait() script.Disabled = false end script.Parent.Touched:connect(OnTouch)
Your issue most probably is because you are refferencing your GUI in the StarterGUI service on studio.
Remember, the GUI's that you have in StarterGUI get cloned to the player's PlayerGUI folder meaning that the changeds have to be done in the player's PlayerGui folder
. Any GUI that you want for example to countdown has to be modified in the player's PlayerGui folder a.k.a the cloned GUI from StarterGUI.
Breaking it down in simple terms:
You apply the scripting to the GUI's that are in the PlayerGUI folder
of the player, not the StarterGui
.
Your code would be as follows:
local plr = game.Players.LocalPlayer; local plrGui = plr:WaitForChild("PlayerGui"); speedGUI = plrGui:WaitForChild("SpeedGUI") countdownGUI = speedGUI:WaitForChild("CounterSpeedGUI"); LabelCount = countdownGUI:WaitForChild("CountLabel"); TouchPart = workspace:WaitForChild("TouchPart"); -- Making sure everything is loaded ^. countdownGUI.Visible = false; -- Visible false local buttonPressed = false; -- Simple Debounce TouchPart.Touched:Connect(function(hit) countdownGUI.Visible = true; if not buttonPressed then buttonPressed = true; for i = 10, 1, -1 do -- Loop to do the countdown. print("Counting down ".. i); LabelCount.Text = "Cooldown: " ..i; wait(1); end LabelCount.Text = "Cooldown: " ..10; countdownGUI.Visible = false; buttonPressed = false; end end)
Remember that doing a for loop is way easier than doing wait() & changing the text manually!
Refference links on the basic stuff used in this code:
http://wiki.roblox.com/index.php?title=Debounce
http://wiki.roblox.com/index.php?title=Loops
http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched