What do you want to achieve? Keep it simple and clear!
Im trying to create a script where when you change teams it will give you a gear.
What is the issue? Include screenshots / videos if possible!
The issue is it wont give the item when you change the team.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked on scriptinghelpers.com to see anything about this and found nothing.
local TeamsService = game:GetService("Teams")
for _, team in pairs(TeamsService:GetTeams()) do
team.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if team.Name == "Soldier" or team.Name == "Raider" then
local clone = game.ServerStorage.AKM:Clone()
clone.Parent = player.Backpack
elseif team.Name == "Civilian" then
if player.Backpack:FindFirstChild("AKM") then
player.Backpack.AKM:Destroy()
end
end
end)
end)
end
You probably want to use player:GetPropertyChangedSignal("Team") instead of doing a PlayerAdded event to each team.
Example below:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function (player)
player:GetPropertyChangedSignal("Team"):Connect(function ()
if player.Team.Name == "Soldier" or player.Team.Name == "Raider" then
-- Do stuff
end
end)
end)
Hello there! Actually, the fun fact is that you don’t need any scripts for that. You can simply past the tools into your team. Example:
If you want a player to receive a tool called “Sword” when they are in a team called “Soldier”, you simply have to move your tool into the team “Soldier”.