Need help on a countdown script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I’m trying to make it so when I click a button a countdown is displayed on the screen.

I tried doing this by using making it so when I click the button it uses a remote event to trigger something that will cause a IntValue to go down and while this IntValue goes down, the timer text label will update itself. if IntValue changes.

I’m new to scripting and I’m not sure what’s wrong with this.

image

Hello! Could you provide a snippet of your code.

timer LocalScript (sorry, my mouse isn’t working well so I will post the other scripts

local intValue = game.ReplicatedStorage.time 

local function updateTextLabel()
	textLabel.Text = tostring(intValue.Value)
end

intValue.Changed:Connect(updateTextLabel) 

Server Script


local remoteEvent = game.ReplicatedStorage.remoteEvents.timerRE
local timerValue = game.ReplicatedStorage.time.Value

remoteEvent.OnServerEvent:Connect(function(player, timer)
	for i = timer, -1, 0 do
		timerValue = i
		task.wait(1)
	end
end)

Button LocalScript


script.Parent.MouseButton1Click:Connect(function(player, timer)
	re:FireServer(player, timer)
end)

How about for the server script? (NP)

I’ve edited the previous reply.

timerValue = i

This is a problem many new scripters face with values! When editing a value instance you actually have to say timerValue.Value = i.

Heres the updated code:

local remoteEvent = game.ReplicatedStorage.remoteEvents.timerRE
local timerValue = game.ReplicatedStorage.time

remoteEvent.OnServerEvent:Connect(function(player, timer)
	for i = timer, -1, 0 do
		timerValue.Value = i
		task.wait(1)
	end
end)

I just moved the .Value from the second line to the timerValue = i line.

I tried this but it didn’t work. Could it be a problem with the RemoteEvent? This timer script was my first time using it.
image

1 Like

Oh your script is in the replicated storage.
I would suggest moving it to ServerScriptService since normal scripts don’t run in the storage services.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.