Simple Obby Timer Script not working?

I made a simple obby timer script that increases the number on a text label every 0.1 seconds, but it doesn’t seem to be working and I’m not sure why?

local Player = game:GetService("Players").LocalPlayer
local Time = 0
script.Parent.Text = Time
while true do
	if Player.leaderstats.Stage.Value > 1 and Player.leaderstats.Stage.Value <= 14 then
		wait(0.1)
		Time = Time + 0.1
		script.Parent.Text = Time
	end
end
2 Likes

You have to do

local Player = game:GetService("Players").LocalPlayer
local Time = 0
script.Parent.Text = tostring(Time)
while true do
	if Player.leaderstats.Stage.Value > 1 and Player.leaderstats.Stage.Value <= 14 then
		wait(0.1)
		Time = Time + 0.1
		script.Parent.Text = tostring(Time)
    else
        wait()
	end
end
2 Likes

Thanks! This seemed to work, but sometimes it goes off by a huge decimal Is there a way to fix this?

image

2 Likes

Yeah!

local Player = game:GetService("Players").LocalPlayer
local Time = 0
script.Parent.Text = tostring(Time)
while true do
	if Player.leaderstats.Stage.Value > 1 and Player.leaderstats.Stage.Value <= 14 then
		wait(0.1)
		Time = Time + 0.1
		script.Parent.Text = tostring(string.sub(tostring(Time), 1, string.len(tostring(Time)) / 3))
    else
        wait()
	end
end
2 Likes

Seems like an inconsistency with this line.

Try replacing it with

Time += 0.1
2 Likes

? That does not do anything, it works the other way too.
It does not throw any errors at you.

1 Like

Like I said, it might be an inconsistency. Its hard to explain so I won’t even bother. Just try it and see what happens @Calum_Dev

1 Like

K but my script works too

local Player = game:GetService("Players").LocalPlayer
local Time = 0
script.Parent.Text = tostring(Time)
while true do
	if Player.leaderstats.Stage.Value > 1 and Player.leaderstats.Stage.Value <= 14 then
		wait(0.1)
		Time = Time + 0.1
		script.Parent.Text = tostring(string.sub(tostring(Time), 1, string.len(tostring(Time)) / 3))
    else
        wait()
	end
end
2 Likes

Hmm this doesn’t seem to work showing this:
image

1 Like

Just tried this and giving back the same thing

2 Likes

You should utilize string.format().

script.Parent.Text = string.format("%.2f", Time)

This will always show 2 decimal points.

1 Like

I think tostring() might actually be the root of the problem here.

Try removing tostring() and just setting the text to the plain number instead.

1 Like

It’s floating point erroring, I doubt it’s tostring().

1 Like
local Player = game:GetService("Players").LocalPlayer
local Time = 0
script.Parent.Text = tostring(Time)
while true do
	if Player.leaderstats.Stage.Value > 1 and Player.leaderstats.Stage.Value <= 14 then
		wait(0.1)
		Time = Time + 0.1
		script.Parent.Text = tostring(string.format("%.3f", tostring(Time)))
    else
        wait()
	end
end

Does this work?

1 Like

Yes. I remember reading an article about it or something.
I think the system has a way of working around it but tostring() could be interfering.

1 Like

@Tylerisawsome113 and @griffeyiscool method by using string.format() work but has excess 0s at the end which is very unnecessary
image

1 Like
local Player = game:GetService("Players").LocalPlayer
local Time = 0
script.Parent.Text = tostring(Time)
while true do
	if Player.leaderstats.Stage.Value > 1 and Player.leaderstats.Stage.Value <= 14 then
		wait(0.1)
		Time = Time + 0.1
		script.Parent.Text = tostring(string.format("%.1f", tostring(Time)))
    else
        wait()
	end
end
1 Like

@Fizzitix This makes it look the same

Try this method, it should work.

local Player = game:GetService("Players").LocalPlayer
local Time = 0
script.Parent.Text = tostring(Time)
while true do
	if Player.leaderstats.Stage.Value > 1 and Player.leaderstats.Stage.Value <= 14 then
		wait(0.1)
		Time = Time + 0.1
		script.Parent.Text = tostring(string.format("%.1f", tostring(Time)))
    else
        wait()
	end
end

Perfect, Thanks so much to everyone who contributed!
image