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

Why is my timer local script not working and can i fix this?

Hi, I was wondering why the Gui doesn't tick down like it should be, ive checked the number value, its been ticking down, but the Gui has not been updating it.

timer gui local script:

while wait() do
	script.Parent.Text = "time left:"..script.Parent.Parent.Time.Value
end

this is the actual timer script its self (this one works feel free to take it, and its in a normal script inside of sss)

game.ReplicatedStorage.RemoteEvents.RemoveCash.OnServerEvent:Connect(function()
	local time = game.StarterGui.Events.Time
	game.StarterGui.Events.TextLabel.Visible = true
	for i = 1,time.Value do
		wait(1)
		time.Value = time.Value -1
	end
	if time.Value <= 0 then
		time.Value = 300
		script.Disabled = true
	end
end)

3 comments

0

You're changing in StarterGui

1 answer

✓ Accepted answer

1:

while wait() do
    script.Parent.Text = "time left:"..script.Parent.Parent.Time.Value
end

^^^this is inefficient do something like this:

local Par =  script.Parent
local Time = Par.Parent.Time

while wait() do
   Par.Text = "time left:"..Time.Value
end

2:

To make the gui appear you have to :FireAllClients() and then .OnClientEvent() in a localscript make the gui appear for example this should be working:

game.ReplicatedStorage.RemoteEvents.RemoveCash.OnServerEvent:Connect(function()
game.ReplicatedStorage.RemoteEvents.RemoveCash:FireAllClients()
end)

The LocalScript:

local plrgui = game.Players.PlayerGui
 local time = plrgui:WaitForChild("Events"):WaitForChild("Time")

game.ReplicatedStorage.RemoteEvents.RemoveCash.OnClientEvent:Connect(function()
    plrgui:WaitForChild("Events"):WaitForChild("TextLabel").Visible = true
    for i = 1,time.Value do
        wait(1)
        time.Value -= 1
    end
    if time.Value <= 0 then
        time.Value = 300
        script.Disabled = true
    end
end)
local Par =  script.Parent
local Time = Par.Parent.Time

while wait() do
   Par.Text = "time left:"..Time.Value
end

I didn't test it but it should work.

2 comments

1

I already got it working but thanks anyways! ill mark yours as the answer since it looks like something that would work! thanks again!

0

No problem!

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