Today i am trying to make Server Timer for my game and having problems with that
What i did: i made remote event for that and firing for all clients here is the code
local timerevent = game.ReplicatedStorage:FindFirstChild("TimerEvent")
local towergenerator = game.ReplicatedStorage:FindFirstChild("TowerGenerator")
local seconds = workspace:FindFirstChild("Timer").Seconds.Value
local minutes = workspace:FindFirstChild("Timer").minutes.Value
local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui:FindFirstChild("TimeGui")
timerevent.OnClientEvent:Connect(function(plr,text)
if seconds <= 0 then
minutes -= 1
seconds = 59
else
seconds -= 1
end
if seconds <= 9 then
gui:FindFirstChild(text).Text = tostring(minutes)..":0"..tostring(seconds)
else
gui:FindFirstChild(text).Text = tostring(minutes)..":"..tostring(seconds)
end
end)
Thanks!
Edit: Output is Argument 1 is missing
gui:FindFirstChild(text).Text = tostring(minutes)…“:”…tostring(seconds)
and
gui:FindFirstChild(text).Text = tostring(minutes)…“:0”…tostring(seconds)
This Lines
The issue is that you’re doing gui:FindFirstChlld(text), and text is not a string. If the text-label’s name is text, then it should be gui:FindFirstChild("text").
I would just handle the seconds on the server, and let the client manage making minutes and seconds from that. I would just have a number-value called Timer in replicated storage that holds the amount of seconds in the timer. We can use string formatting to form minutes and seconds from that. I would also use WaitForChild as opposed to FindFirstChild, as not everything may have loaded before the script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Player")
local timerEvent = ReplicatedStorage:WaitForChild("TimerEvent")
local timerIndicator = ReplicatedStorage:WaitForChild("Timer")
local localPlayer = Players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local timeGui = playerGui:WaitForChild("TimeGui")
local timeLabel = timerGui:WaitForChild("Text")
function formatTime(seconds)
return string.format("%d:%02d", math.floor(seconds / 60), seconds % 60)
end
function updateTime()
local timerValue = timerIndicator.Value or 0
timeLabel.Text = formatTime(timerValue)
end
timerEvent.OnClientEvent:Connect(updateTime)