I’ve been working on my game recently and I wanted to make a Timer, with a twist to it.
I wanted to make the timer Tick or count up, so fx. 00:00:00 then 00:00:01
Instead of, 00:00:01 then 00:00:00, and further beyond.
The problem is that I’m not an experienced scripter.
I don’t know how to make this happen and it’s one of the most important features in my game to be made.
If you know how to make it work, and want to help me out then you are free to say something in the replies.
You could do something like this. This will just print out but you could also use this for a text label.
local Maxseconds = 5000
for i = 1, Maxseconds,1 do
wait(1)
local minutes = math.floor(i/60)
local hours = math.floor(minutes/60)
local seconds = i - (minutes * 60)
minutes -= hours * 60
print(hours..":"..minutes..":"..seconds)
end
local Maxseconds = 5000
local TextLabel = script.Parent
for i = 1, Maxseconds,1 do
wait(1)
local minutes = math.floor(i/60)
local hours = math.floor(minutes/60)
local seconds = i - (minutes * 60)
minutes -= hours * 60
TextLabel.Text = hours..":"..minutes..":"..seconds
end
Works Very well. Now here is the part that I’ve wanted to make mainly,
There is a timer that starts when the server starts running. When you touch a specific part it resets back to 0 Do you know how to make that? You do not have to respond if you don’t want to this is just a question.
Put a bool value in replicated storage and name it “Touched”. Then do this for the local script:
local Maxseconds = 9999
local TextLabel = script.Parent
local BoolVal = game.ReplicatedStorage:WaitForChild("Touched")
while true do
for i = 1, Maxseconds,1 do
if BoolVal.Value == true then break end
wait(1)
local minutes = math.floor(i/60)
local hours = math.floor(minutes/60)
local seconds = i - (minutes * 60)
minutes -= hours * 60
TextLabel.Text = hours..":"..minutes..":"..seconds
end
repeat wait() until BoolVal.Value == false
end
Then put this as a server script, make it a child of the part that they have to touch
local db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and db == false then
db = true
game.ReplicatedStorage.Touched.Value = true
wait(3)
db = false
game.ReplicatedStorage.Touched.Value = false
end
end)
I don’t know if this will work, if it doesn’t then I can come up with another solution.
local Maxseconds = 9999
local TextLabel = script.Parent
local BoolVal = game.ReplicatedStorage:WaitForChild("Touched")
while true do
for i = 1, Maxseconds,1 do
if BoolVal.Value == true then break end
wait(1)
local minutes = math.floor(i/60)
local hours = math.floor(minutes/60)
local seconds = i - (minutes * 60)
minutes -= hours * 60
minutes, hours, seconds = tostring(minutes), tostring(hours), tostring(seconds)
if string.len(minutes) < 2 then minutes = "0"..minutes end
if string.len(hours) < 2 then minutes = "0"..hours end
if string.len(seconds) < 2 then minutes = "0"..seconds end
TextLabel.Text = hours..":"..minutes..":"..seconds
end
repeat wait() until BoolVal.Value == false
end