Hello Developers, Today I’ve been working on my game again like I do most of the time and noticed something really important to fix.
I need to change a local script to a server script for a handful of reasons.
I need the timer to be a server script so that players timers match up with other’s timers
I need to have the timer to be running even when a player resets.
Ext.
So, The script I have is a script that makes a timer function. (Note, the timer goes up instead of going down.)
This is where the code is located, (child) and the code is below this message and screenshot.
local startTime = os.clock()
local TextLabel = script.Parent
local BoolVal = game.ReplicatedStorage:WaitForChild("Touched")
local function sToHMS(s)
local h = math.floor(s/3600)
s = s % 3600
local m = math.floor(s/60)
s = s % 60
return string.format("%02i:%02i:%02i", h, m, s)
end
game:GetService("RunService").RenderStepped:Connect(function()
if BoolVal.Value then return end
TextLabel.Text = sToHMS(os.clock() - startTime)
end)
This is the text label code, that works together with the Touch detection system, which you can see below this text.
--------------------------------------------------------------------- Timer
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)
So, the question is how do I make this a server script if needed to, so that it can
Sync with other timers (other players)
Still, be running while a player resets
Be a global timer so all players see the same
Does anyone know how to do this?
If yes, then let me know in the replies if you are willing to help
You can change all timers at once in a ServerScript, and fire a remote event to all clients to show on their client. And you can use player.CharacterAdded for the ServerScript to run when the player dies too.
My apologies, I thought you where asking how do so in general,
You can’t change this full local script to a normal script as this is client sided only, so I would assume you would just have to use a different method of what you’re currently trying to do.
You can make so when the first player joins the server, it calculates the timer and fires a message to the server regarding about the timer.
Then everytime someone joins, it fires a client to that player so their timer is synced with the server’s timer which was created due to the first player who joined in the server.
After the player recieves the client message, you can do a code that every one second it updates the timer.
Put a string value in ReplicatedStorage, then change the value of that string value with a server script in ServerScriptService. Then on the client, reference the string value and you can use the .Changed event to detect when it changes. Then when it changes, set the textlabe’s text to the value of the string value.