Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

0
Thank you, all I had to do was put player inside of the brackets just like you said DaBagelBoy 90 — 4y
Ad

Answer this question