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

My timer won't work properly in game. (It works normal in studio)?

Asked by 6 years ago

Problem: https://gyazo.com/c6026f63c977e2106d40667297653580 If you don't want to click: The timer should go like this: 02:01 02:00 01:59 but instead it goes 02:01 02:00 02:59 01:58

game.ReplicatedStorage.Timer.Changed:connect(function()
        if game.ReplicatedStorage.Timer.Value == -1 and game.ReplicatedStorage.Timer2.Value > 0 then
game.ReplicatedStorage.Timer2.Value = game.ReplicatedStorage.Timer2.Value - 1
game.ReplicatedStorage.Timer.Value = 59

end
end)

2 answers

Log in to vote
0
Answered by 6 years ago

Instead of using two values, one for minutes, and one for seconds, why don't you try to use one int value, for seconds. Try this:

local timer = game.RepliactedStorage.Timer.Value
if timer > 0 then
timer = timer - 1
end

And to get the amount of minutes/seconds passed:


local minutes = math.floor(timer/60) local seconds = timer - (minutes*60) print(minutes..":"..seconds)

Lets say timer was 72 in that situation, that would be it would divide it by 60. 72 / 60 = 1.2. Now we floor it, so it's 1. That 1 represents 60 seconds, so now all we need to find are seconds. The timer currently has how many seconds there are, so all we need to do is subtract the minutes * 60 (seconds stored in the minutes variable) from timer and we get the amount of seconds passed, the seconds variable will always be below 60.

I hope I helped, and if you need more help just ask! :D

Ad
Log in to vote
0
Answered by 6 years ago

What do you use to manipulate your timer (second)? I changed '-1' to '0' , Hmmmmm?

game.ReplicatedStorage.Timer.Changed:connect(function() 
        if game.ReplicatedStorage.Timer.Value == 0 and game.ReplicatedStorage.Timer2.Value > 0 then
game.ReplicatedStorage.Timer2.Value = game.ReplicatedStorage.Timer2.Value - 1
game.ReplicatedStorage.Timer.Value = 59

end
end)

Answer this question