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

How do i tart a timer manually?

Asked by 4 years ago
Edited 4 years ago

ive made a timer that starts as soon as the game starts i want to be able to start the timer with like a button, how can I do that?

2 answers

Log in to vote
0
Answered by 4 years ago

It kind of depends on how your current timer is working. Is your timer supposed to work like a stopwatch or countdown?

In both cases you should be able to just spawn a separate thread which runs some long-lived code in it (like a while loop) which slowly increases/decreases your timer.

Ad
Log in to vote
0
Answered by 4 years ago

Your question was very vague but let me give you the best answer. The first thing we need to do is to create the button. We need to create a ScreenGui in StarterGui. From there we need a frame, create a frame and make sure its a child of that ScreenGui. Position your frame however you want to, now you need to add a TextButton. Once thats created and its positioned to your liking we need to create a localscript inside the Button. Lets get down to some basic coding.

--Local Script inside Text Button,

--Variables
local button = script.Parent -- The text button
local countdown = 500 -- What number do you want the countdown timer to start at
local clicked = false --This will change to true when the button is pressed

--Functions
button:MouseButton1Click:Connect(function()
        if clicked == false then --Allowed you to stop your countdown
        clicked = true
end 
       if clicked == true then
       clicked = false
end 
end)
while clicked do -- while clicked is true loop
countdown = countdown - 1 -- Subtracting 1 second from countdown
wait(1) -- Waiting 1 second before looping

On the other hand if you want a stopwatch we can use our previous code

--Local Script inside Text Button,

--Variables
local button = script.Parent -- The text button
local stopwatch = 0 -- What number do you want the countdown timer to start at
local clicked = false --This will change to true when the button is pressed

--Functions
button:MouseButton1Click:Connect(function()
        if clicked == false then --Allowed you to stop your stopwatch
        clicked = true
end 
       if clicked == true then
       clicked = false
end 
end)
while clicked do -- while clicked is true loop
countdown = countdown + 1 -- adding 1 second to your stopwatch
wait(1) -- Waiting 1 second before looping

Hope this helped

0
thanks alot! fnaticOlofMisterXd 2 — 4y
0
For sure, could you accept my answer it helps me out and other scripters Skippy_Development 59 — 4y

Answer this question