Gear not giving when team is changed

  1. 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.
  2. What is the issue? Include screenshots / videos if possible!
    The issue is it wont give the item when you change the team.
  3. 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)
1 Like

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

3 Likes

Wouldn’t this only be for when the player is joined into the game? And either way this doesn’t seem to help or give me the gear.

I did not know this too be a thing. And I believe you mean something by this?image

Yep, that’s it! :smile: Hope this may help you!

1 Like