What do you want to achieve? Keep it simple and clear!
I want to convert my timer from seconds to minutes in the script below.
What is the issue? Include screenshots / videos if possible!
When I try to convert my seconds to minutes nothing works and I’ve tried for the past week. I hope somebody can give me guidance!
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve looked all over youtube and I even asked the forum here but nothing seems to work and I’m somewhat clueless about where to put everything because I’m fairly new to scripting! Also let me know if I need to create a folder in the developer hub because I can since I have my timed remoteevent named “BestTime” and I have my checkpoint sound that plays when you step on one of my checkpoints! Script below:
local currentTime = 0
local timerStopped = false
local Runservice = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local personalBest = player:WaitForChild("PersonalBest") or math.huge
local replicatedStorage = game:GetService("ReplicatedStorage")
local textLabel = script.Parent
textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
personalBest.Changed:Connect(function()
textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
end)
function onStartTouched(hit)
timerStopped = false
startTime = tick()
currentTime = 0
Runservice.RenderStepped:Connect(function()
if not timerStopped then
currentTime = tick() - startTime
textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
end
end)
end
function onEndTouched(hit)
if not timerStopped then
timerStopped = true
if currentTime > 0 and currentTime < personalBest.Value then
personalBest.Value = currentTime
replicatedStorage.BestTime:FireServer(currentTime)
end
textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
end
end
workspace:WaitForChild("StartTimer").Touched:Connect(onStartTouched)
workspace:WaitForChild("EndTimer").Touched:Connect(onEndTouched)
Oh wait! Do you recommend that I replace those 2 lines that I sent with the code you sent or do I just fill it in? I’m just confused on where to put everything because I’ve never done anything like this in my life. I changed it to this below I don’t know if its correct or not:
local currentTime = 0
local timerStopped = false
local Runservice = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local personalBest = player:WaitForChild("PersonalBest") or math.huge
local replicatedStorage = game:GetService("ReplicatedStorage")
local textLabel = script.Parent
textLabel.Text = "Timer: " .. tostring(math.floor(seconds / 60)) .. ":" .. tostring(seconds % 60)
.. "\nPersonal Best: " .. tostring(math.floor(bestSeconds / 60))..":"..tostring(bestSeconds % 60)
function onStartTouched(hit)
timerStopped = false
startTime = tick()
currentTime = 0
Runservice.RenderStepped:Connect(function()
if not timerStopped then
currentTime = tick() - startTime
textLabel.Text = "Timer: " .. tostring(math.floor(seconds / 60)) .. ":" .. tostring(seconds % 60)
.. "\nPersonal Best: " .. tostring(math.floor(bestSeconds / 60))..":"..tostring(bestSeconds % 60)
end
end)
end
function onEndTouched(hit)
if not timerStopped then
timerStopped = true
if currentTime > 0 and currentTime < personalBest.Value then
personalBest.Value = currentTime
replicatedStorage.BestTime:FireServer(currentTime)
end
textLabel.Text = "Timer: " .. tostring(math.floor(seconds / 60)) .. ":" .. tostring(seconds % 60)
.. "\nPersonal Best: " .. tostring(math.floor(bestSeconds / 60))..":"..tostring(bestSeconds % 60)
end
end
workspace:WaitForChild("StartTimer").Touched:Connect(onStartTouched)
workspace:WaitForChild("EndTimer").Touched:Connect(onEndTouched)
Oh Lord it only shows “Label” now and not the times! You mind looking at the updated script I sent above your last comment and checking what mistakes I made? It’s saying “unknown global ‘seconds’
local currentTime = 0
local timerStopped = false
local Runservice = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local personalBest = script:WaitForChild("PersonalBest") or math.huge
local replicatedStorage = game:GetService("ReplicatedStorage")
local textLabel = script.Parent
local function round(number) -- round to 3 decimal places
number *= 1000
number = math.floor(number)
number = number / 1000
return number
end
local function Format(Int)
return string.format("%02i", Int)
end
local function convertToMS(Seconds)
Seconds = round(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
return Format(Minutes)..":"..Seconds
end
local function UpdateText()
textLabel.Text = "Timer: " .. convertToMS(currentTime) .. "\nPersonal Best: " .. convertToMS(personalBest.Value)
end
personalBest:GetPropertyChangedSignal("Value"):Connect(UpdateText)
function onStartTouched(hit)
timerStopped = false
local startTime = tick()
currentTime = 0
Runservice.RenderStepped:Connect(function()
if not timerStopped then
currentTime = tick() - startTime
UpdateText()
end
end)
end
function onEndTouched(hit)
if not timerStopped then
timerStopped = true
if currentTime > 0 and currentTime < personalBest.Value then
personalBest.Value = currentTime
replicatedStorage.BestTime:FireServer(currentTime)
end
UpdateText()
end
end
workspace:WaitForChild("StartTimer").Touched:Connect(onStartTouched)
workspace:WaitForChild("EndTimer").Touched:Connect(onEndTouched)
Yo I think it might be me doing something wrong because I copied and pasted your script but now my gui only displays “label” as the timer in test mode! Any idea of what I should do? Like rename my gui or something?
Here are the steps to ensure the script is correctly linked to your GUI:
Make sure the script is a child of the GUI element in the hierarchy.
The script should be placed in the same location as the GUI element you want to control. For example, if your GUI is in the StarterPack, the script should also be in the StarterPack.
Ensure that the GUI element has a TextLabel or a similar object to display the timer text.
Double-check the spelling and capitalization of the GUI element’s name in the script. It should match the actual name of the GUI element in the hierarchy.
Is the ScreenGui in StarterGui and have you made sure you checked the exact TextLabel? It works fine for me, perfectly.
For the reply above, all the points recommended by him or should I say
ChatGPT have already been done.
Edit it has already been solved please send a post that solved the problem then mark it as a solution so people don’t get confused