Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GUI Timer (Seconds, Milliseconds) until part touch?

I would like to create a script that would link to GUI text, counting up by seconds.

I am aiming to create something like this, but counting up.

Also, I want to stop the timer when I collide with a certain object/part.

Here is what I have so far:

local time = 0  
for i = 1, 89934 do
wait(0.1) 
time = time + 0.1 
script.Parent.Text = tostring(time) 
end

Location: StarterGUI>ScreenGUI>TextButton>Script

Also, the timer resets every time you die, is there a way to prevent this?

Thanks in advance, -MexheCo

4 comments

0

You shouldn't be using scripts to handle gui coding. Use a local script.

0

You should be using a (while do) loop rather than the (for do) loop.

0

You can stop the timer using a condition value. while hitpart == false do (timer loop) end. and then turn hitpart true by using Touched on the certain object.

0

Easier said than done. OP will need a RemoteEvent to do this.

1 answer

✓ Accepted answer

###There is a property in StarterGui called ResetPlayerGuiOnSpawn. If unticked, the PlayerGui (which holds the guis) will not reset. According to your hierarchy, you've use a server script to accomplish this, GUI coding is client-side only.

--LocalScript under TextButton

for i = .1, 10, .1 do
    script.Parent.Text = tostring(i)
end

###In the for loop, the first .1 is the starting number, 10 is the desired number, and the last .1 is the increment. Not providing the increment will default it to 1.

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.