How do I convert this localscript to a server script to make the time replicate?

This is the localscript. I want to be a server script so that the time replicates across other clients.

local parent = script.Parent
local player = game.Players.LocalPlayer
local leaderstats = player.leaderstats
local TimeStat = leaderstats and leaderstats:FindFirstChild("Time")
local Highscore = leaderstats and leaderstats:FindFirstChild("TopTime")
parent.Parent = script.Parent.Parent.Head

wait(1)

while wait(0) do
	if player.Character:FindFirstChild("ForceField") then
		parent.TimeLabel.IsInSpawn.Value = true
	else
		parent.TimeLabel.IsInSpawn.Value = false
	end
	
	if parent.TimeLabel.IsInSpawn.Value == false and player.Character.Humanoid.Health ~= 0 then
		parent.TimeLabel.Time.Value = parent.TimeLabel.Time.Value + 1
		parent.TimeLabel.Text = parent.TimeLabel.Time.Value
		TimeStat.Value = parent.TimeLabel.Time.Value
		if TimeStat.Value > Highscore.Value then
			Highscore.Value = TimeStat.Value
		end
	wait(1)
	end
end


player.Character:WaitForChild("Humanoid").Died:Connect(function()
	parent.TimeLabel.Time.Value = 0
end)

First, you need to create a RemoteEvent in ReplicatedStorage called “Time”. Then, whenever you change the time value, fire the remote event to the server and you can then use that data to replicate it to all clients.

2 Likes

Use remote functions if you wanna do this.

The client doesn’t need any values returned from the server so RemoteEvent would be a more appropriate option.

RemoteFunctions work too however.

Is your method able to be exploited?

Well imagine if an exploiter can change any value sent to the server. If it’s game breaking or very important, then do the time checking for all players on the server instead of the client. If it won’t bother you if a value is changed, then don’t worry about it.

It does bother me though because I don’t want exploiters changing their leaderboard values and getting things they aren’t supposed to have.

I’m not sure if clients can change the value since I tried it myself in roblox studio