Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make a timer that will show the timer and move two blocks?

Asked by 3 years ago
Edited 3 years ago

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.

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
I'm sorry but how would I put a server script on my text label. And also an explanation on what this does and what I did wrong would be nice TheOof1sout 4 — 3y
0
basically a server script is a regular script GameBuilderLol 58 — 3y
0
Actually It just turns out I had to put the script that I posted here into a regular or server script TheOof1sout 4 — 3y
0
Yes thats right GameBuilderLol 58 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

0
It didn't work but I tried to get the script to to print 30 outside of the repeat loop but in the output it wasn't there. So it seems as if your code isn't the problem, but the script isn't being called on at all because nothing's happening. any reason as to why this could be caused I'm using a local script under the part might I add TheOof1sout 4 — 3y
0
actually Nvm it's working now, I just needed to have my code in a regular script thanks for the las part though, I will try TheOof1sout 4 — 3y
0
the last part you recommended worked but I didn't to use repeat as an alternative TheOof1sout 4 — 3y
0
I didnt tested it before putting it in lol acediamondn123 147 — 3y

Answer this question