Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Playerstarterscript Timer Glitching, How to not make it not repeat when its running already?


local Chee = script.Parent.Parent.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame"):WaitForChild("TextBox")

local bacon = script.Parent.Parent:WaitForChild("Folder"):WaitForChild("Timer")

local Player = game.Players.LocalPlayer

bacon.Changed:connect(function(prop)
    print(prop)

do Chee.Text = bacon.Value
 
for i=1,bacon.Value do
wait(1)
		bacon.Value = bacon.Value - 1
		Chee.Text = bacon.Value
if bacon.Value == 0 then
end


end
end
end)

My Gui/Playerscript/localscript isn't working, it keeps running I=1,Bacon.Value every time its changed.

How do you make it so The I=1,Value only runs once when it's changed?

Also Bonus question: How do you get a player's Character from a Localscript?

Help would be greatly appreciated TuT'

1 comment

1

How to get a Character from local script: local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:wait()

1 answer

✓ Accepted answer

I'm not really sure what you're doing as the script progresses. You have some incorrect tabbing and your syntax may have problems. Lets show you what to do from start to finish.

First, make sure this script is a localscript, all GUI's should be ran with a localscript because only the client should see it. Client being a persons computer. Now with ONLY a local script, you can get the player by doing this

local Player = game.Players.LocalPlayer

This will not work in a Script.

Now that we know how to get the player, let's change the way you're getting ScreenGui and such;

local Chee = Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame")
local bacon = Player.PlayerGui:WaitForChild("Folder"):WaitForChild("Timer")

As you see, this is a shorter, and probably preferred way to get the Children of PlayerGui and so on.

  • Now the actual part of your code, I'll just show you how it should actually look like.
while wait(1) do	
	bacon.Value = bacon.Value - 1
	Chee.Text = bacon.Value
	if bacon.Value == 0 then
		break
	end
end

The whole script is:

local Player = game.Players.LocalPlayer
local Chee = Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame")
local bacon = Player.PlayerGui:WaitForChild("Folder"):WaitForChild("Timer")

while wait(1) do	
	bacon.Value = bacon.Value - 1
	Chee.Text = bacon.Value
	if bacon.Value == 0 then
		break
	end
end

If you have a question or something, just comment bellow.

This discussion is preserved as it was. New answers, comments, and votes are closed.