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