Why wont this script update/change the value?

local timeRemaining = script.Parent.Value.Value

while timeRemaining > 0 do
	print("Seconds remaining: " .. timeRemaining)
	script.Parent.Text = timeRemaining
	wait(1)
	timeRemaining = timeRemaining - 1	
end

print("Timer reached zero!")

Maybe you can change the gui text using PlayerGui.

1 Like

Ahhh but i would have to change ALL the players gui for it to work; and what if some players join in late? Also i checked playerGUI and it didnt change either.

It’s a local script right?

1 Like

It is. do i need to change that to a script?

No it’s ok, it should be a local script

1 Like

Is there any error in the output so we can make a guess.

1 Like

You’re are defining the value of the baseValue outside the loop. So for example, lets say when the script runs the value of your intValue is 10. In your first line when you do Value.Value you are basically saving 10 and defining it as “timeRemaining”. Now whenever you use the variable timeRemaining you are simply referencing the number 10.

What you should do is add the .Value inside the loop so you get the current Value.

local timeRemaining = script.Parent.Value

while timeRemaining.Value > 0 do
	print("Seconds remaining: " .. timeRemaining.Value)
	script.Parent.Text = timeRemaining.Value
	wait(1)
	timeRemaining.Value = timeRemaining.Value - 1	
end

print("Timer reached zero!")

Note I’m on mobile so there may be typos. Also alternatively instead of using a while loop, you could use a for loop. Also just to avoid confusion you should give your int/number value a unique name so you don’t get confused with “Value.Value”

1 Like


It has counted down to Zero but has not changed on my value.

It is because you are looking at the value from StarterGui. It just inserts the stuff, which are the children of StarterGui, to PlayerGui. Try looking at it in Players. The value will be shown if you look at it from the Players service.

Value1

Value2

1 Like

Ahhh it does show, but what happens when another player joins late, or how will i know which one to check if its on zero?

This will not work in a local script. Whatever happens in the local script, it’s ONLY seen by the player. I recommend doing this in a normal script and setting the value there (put the value in ReplicatedStorage), but in a local script you do:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

ReplicatedStorage.Value:GetPropertyChangedSignal("Value"):Connect(function()
  -- Set the text to the value of the value.
end)
1 Like

I think you should move the value to ReplicatedStorage because as you mentioned about it above, it will be shown if the player is in the server but when someone comes to the server the value won’t have been valid for him or her. You should handle it via the server.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeRemaining = ReplicatedStorage:WaitForChild("Value")

while timeRemaining.Value > 0 do
    print("Seconds remaining: " .. timeRemaining.Value)
    wait(1)
    timeRemaining.Value -= 1	
end

And use the script @WooleyWool wrote it above in a local script.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeRemaining = ReplicatedStorage:WaitForChild("Value")

timeRemaining:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = timeRemaining.Value
end)
1 Like

This portion is incorrect, this function needs to see if the instance’s property changed, not the property’s property. Fixed code:

timeRemaining:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = timeRemaining.Value
end)

and for the sake of having the value reach 0 rather than stopping at 1, do the following in the server script:

while timeRemaining.Value >= 0 do
    print("Seconds remaining: " .. timeRemaining.Value)
    wait(1)
    timeRemaining.Value -= 1	
end
local timeRemaining = script.Parent.Value

local runService=game:GetService("RunService")
runService.RenderStepped:Connect(function()
	print("Seconds remaining: " .. timeRemaining.Value)
	script.Parent.Text = timeRemaining.Value
	wait(1)
	timeRemaining.Value -= timeRemaining.Value
end)

the problem is you are just decreasing number from another number instead of changing the actual value of the reference

local timeRemaining = script.Parent.Value

while wait(1) do
    if timeRemaining > 0 then
    timeRemaining -= 1	
	script.Parent.Text = timeRemaining
    print("Seconds remaining: " .. timeRemaining)
    end
end

what id do
also is it a script or a local scripT?

you are making a variable equal to the value of the value, not the instance . the script below should work .
local timeRemaining = script.Parent.Value

    while timeRemaining > 0 do
    	print("Seconds remaining: " .. timeRemaining)
    	script.Parent.Text = timeRemaining
    	wait(1)
    	timeRemaining.Value  -= 1
end

print("Timer reached zero!")

You could Fire All Clients from a server script to local script to receive the value.

1 Like

When the value is 1, it will take some time to reach 0, I meant it will wait 1 second more. So it is not necessary.