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