If I wanted to give someone tools based on their team, would the script be a local or a server script? I am a bit confused.
ServerScript obviously. You just check which team the player is on from the server and parent a clone of the tool to their backpack.
So how would I define player, if it’s a server script?
And of course I don’t want everyone on the team to get tools whenever someone from their team respawns.
That’s pretty easy actually. You just create separate RBXScriptConnection
s for every player for Player.CharacterAdded
event and just check player’s team inside the function that is connected to the event.
At the very basic level it would look like this:
local PlayersSevice = game:GetService("Players")
PlayersService.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if Player.Team ~= nil then
for Index, Value in ipairs(Player.Team:GetChildren()) do
Value:Clone().Parent = Player.Backpack --Assuming you use the built in Teams Service and you put all team specific tools under the team instances accordingly.
end
end
)
)
That’s ok, but the PlayerAdded event is when they join… and they are not instantly on this team. Correct me if I am wrong.
Yes, that’s why I added CharacterAdded event inside the PlayerAdded event so the function runs every time player respawns.
Ah my bad, by the time you replied, I realised. Cheers bro!