How to change a local script to a server script?

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.

  1. I need to change a local script to a server script for a handful of reasons.
  2. I need the timer to be a server script so that players timers match up with other’s timers
  3. I need to have the timer to be running even when a player resets.
  4. Ext.

So, The script I have is a script that makes a timer function. (Note, the timer goes up instead of going down.)

image 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. image

--------------------------------------------------------------------- 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

  1. Sync with other timers (other players)
  2. Still, be running while a player resets
  3. 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 :smiley:

2 Likes

You can’t change a local script to a script through a script. You can with plugins but only in studio.

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.

Not with a script, but change it from a local script to a script. Do you know if there is a plugin that does it or do you know a name of one?

I don’t know any myself, I just know it’s possible according to the api documentation. You can always just copy and paste, of course.

Doesn’t work like that, already tried it. There are some things that only work for local scripts that can’t function in the global script

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.

It’s like how he did it in this video:
https://www.youtube.com/watch?v=ESzmiC_AzLw