I'm trying to make a script that'll show the timer on a block using a SurfaceUI and then when the timer runs out, a door opens(Two blocks split apart from each other). But while trying to get the time script to work, nothing happened. The timer doesn't start at all. This is my script
local seconds = script.Parent.Parent.Timer --The value of the start of the timer script.Parent.Text = seconds.Value --Mapping the text to the timer value for i = 1, seconds.Value do --The script to get rid of one number from the value every second wait(1) seconds.Value = seconds.Value - 1 script.Parent.Text = seconds.Value end
This script is a local script in the part of the block I want to use as a timer
I don't have a script for opening the doors and I'd like to ask how exactly I'm supposed to do that while I'm here.
Edit: for future users stumbling upon this post I just want to say that my mistake is that I used a local script for my code. If you don't want to use remote events then in order to interact with other objects in different places you need to use regular scripts.
Put a server script on your surface gui's textlabel and then type this:
local seconds = script.Parent.Parent.Timer --gets the timer while wait() do script.Parent.Text = seconds.Value --constantly sets it's text to the timer's value end
Try using Repeat
for an alternative?
Example:
local Seconds = script.Parent.Parent.Timer.Value script.Parent.Text = Seconds repeat Seconds = Seconds - 1 script.Parent.Text = Seconds wait(1) until Seconds == 0
if ur gonna run something when seconds is 0 then use if statement
if Seconds <= 0 then -- Stuff ? end
If it works tell me