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

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

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)

1 comment

0

No, do NOT include the player parameter on OnClientEvent

2 answers

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.

2 comments

0

So where should I relocate it to?

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.

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)

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