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

How do I make the FireClient have a player peramater in this situation?

Asked by 5 years ago

Here I have this script in the workspace in a model, and the model has a table of players that it successfully always gets, but I need the FireClient to have a player parameter in it which I don't understand how to do:

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

I need help making that script have a player parameter in it and if someone could explain how that'd be awesome. It ties into this local script that then is supposed to change the players' team to Sea green:

script:WaitForChild("TeamChangeEasy")

script.TeamChangeEasy.OnClientEvent:connect(function(player)
    player.TeamColor = BrickColor.new("Sea green")
end)
0
No, do NOT include the player parameter on OnClientEvent User#19524 175 — 5y

2 answers

Log in to vote
0
Answered by
Pojoto 329 Moderation Voter
5 years ago

In line 3 of your code where you call FireClient(), you need to specify the player who you want to change the team of. Wherever you reference the player in your server script you should put that in the parentheses of FireClient().

In your local script get rid of the "player" written inside of script.TeamChangeEasy.OnClientEvent:connect(function(player).
The client doesn't need a player parameter, it already knows itself.

There's also another problem, you have the RemoteEvent located in a backpack! You're trying to access many things that can't be accessed, and I suggest you try to do more research on RemoteEvents and how the client-server communication works.

0
So where should I relocate it to? Supergamerboy1995 129 — 5y
0
You should always place RemoteEvents in the 'ReplicatedStorage'. We do this because ReplicatedStorage is accessible by the client and server, so the RemoteEvent works there. Pojoto 329 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

You can pass v for the player parameter when calling FireClient(player) like this:

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

Looking at this chunk of code you should remove the player argument since it's a local script anyways you can reference the local player easy.

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

Also using connect is deprecated which means you should not try to use it anymore so please try typing Connect

Correct way of creating your event signal

script.TeamChangeEasy.OnClientEvent:Connect(function()

end)

Wrong way:

script.TeamChangeEasy.OnClientEvent:connect(function()

end)

Answer this question