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

Am I doing this remote event the wrong way? Help?

Asked by 6 years ago

So I tried to make a remote event that goes from a server script to a client script to change the teamcolor of a player because that cannot be done locally in a server script. In the server script in the model I have the script:

for i,v in pairs(model.PlayersTouching:GetChildren()) do
        if v:FindFirstChild("Backpack") then
            v.Backpack.ChangeTeamEasy.TeamChangeEasy:FireClient()
    end
end

This then goes to a script in the starter pack that parents back to the main local player that has the TeamColor property which I had tried to change using this script that's in the Starterpack, along with a remote event api inside the script:

script:WaitForChild("TeamChangeEasy")

script.TeamChangeEasy.OnClientEvent:connect(function()
    script.Parent.Parent.TeamColor = BrickColor.new("Sea green")
end)

However it still has not been successful. Could anyone help me figure out why not?

0
Because FireClient needs a Player to fire. User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by
waifuSZN 123
6 years ago

The :FireClient event needs a player parameter when it is used, because you are firing an event to the player's specific client.

Ad
Log in to vote
0
Answered by
Kev_nn 4
6 years ago

A remote event allows scripts and local scripts communicate with each other. Because a local script comes from a player's client, you must have the parameter for the player.

To fix your code, it would be this:

script:WaitForChild("TeamChangeEasy")

script.TeamChangeEasy.OnClientEvent:connect(function(plr) --Your first parameter MUST be the player!
   script.Parent.Parent.TeamColor = BrickColor.new("Sea green")
end)

Note: When firing a remote event from a local script, you DO NOT need to have a player parameter. Only on the OnClientEvent function.

Also, keep in mind that if you ever use remote events in the future with extra variables, the player must always be the first parameter listed.

Answer this question