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

GUI Timer (Seconds, Milliseconds) until part touch?

Asked by
MexheCo 46
6 years ago
Edited 6 years ago

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

0
You shouldn't be using scripts to handle gui coding. Use a local script. User#19524 175 — 6y
0
You should be using a (while do) loop rather than the (for do) loop. LostPast 253 — 6y
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. LostPast 253 — 6y
0
Easier said than done. OP will need a RemoteEvent to do this. User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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.

0
Thanks! MexheCo 46 — 6y
Ad

Answer this question