I want respawn the players but this error is getting.. How to fix this?

Error: OnClientEvent can only be used on the client

My script (All is in Script and not LocalScript and positioned in ServerScriptService):

First script:

for _, p in ipairs(game.Players:GetChildren()) do
	game:GetService('ReplicatedStorage').Events.RemoteEvent.LoadChar:FireClient(p)
--	p.Character.Humanoid.Health = 0
--	p.Character:LoadCharacter()
end

Second script:

game:GetService("ReplicatedStorage").Events.RemoteEvent.LoadChar.OnClientEvent:connect(function(player)
	player:LoadCharacter()
end)

3 comments

0

LoadCharacter can only be used in a server script.

0

The second script has to be a local script, and the first a server script.

0

OnServerEvent can only be used on the server