Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone explain to me how I would go about making a server to client RemoteEvent?

I wanted to make a script so that when a player dies, their camera is reset to the default one. Since Humanoid.died only works on the server side, and Enum.CameraMode only works on the client side, I did some research and discovered that I needed to use remote events.

Server Script:

toggle = false

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			toggle = true
			game.ReplicatedStorage.RemoteEvent:FireClient()
			print("ToggledOn")
			print("SentToClient")
			toggle = false
		end)
	end)
end)

local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()

if toggle == false then 
	print("ToggledOff")
	
end
end)

I believe it should fire a remote event to the client script. (I don't really understand Remote Event that much.)

LocalScript:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(player)
	print("RecievedFromServer")
	game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
end)

so they should both print something but I don't see the recieve or sent message. All I see is this in the output: Argument 1 missing or nil

can someone help me with this?

1 answer

✓ Accepted answer

The FireClient function requires the player that the RemoteEvent will be firing to. If you leave it as nil then the RemoteEvent won't know what client to fire to and therefore it will error. Just put the player inside of the FireClient parameters and it should work.

Also, OnClientEvent doesn't have a player parameter as you can see here.

1 comment

0

Thank you, all I had to do was put player inside of the brackets just like you said

This discussion is preserved as it was. New answers, comments, and votes are closed.