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

How do I make it so group tools are removed if the player changes teams?

So, basically I managed to make a script that gives members of a group tools, however, if players who are in the group change their team, they still keep their group tools (I'd like to mention that when you change team, you also die). I know I am meant to add some condition that if the player changes their team, then the tools they received as group members are meant to be destroyed, however I am not certain how to do it. I would really appreciate the help.

Here is the script:

groupID = 2827623

tools = game.ServerStorage:GetChildren()
game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		
		if player:GetRankInGroup(groupID) > 1 then
			for i = 1, #tools do
			if tools[i].Name == "SomeTool1" then
				local c = tools[i]:Clone()
				c.Parent = player.Backpack
				end
			end
		elseif player:GetRankInGroup(groupID) == 1 then
			for i = 1, #tools do
			if tools[i].Name == "SomeTool2" then
				local c = tools[i]:Clone()
				c.Parent = player.Backpack
				end
			end
		end
	end)
end)

1 answer

✓ Accepted answer

Because your kill the character when you change teams, the tools will be automatically removed. Also because of this, all you need to do is check to see which team the player is on when they respawn.

local teamWithTools = BrickColor.new("Bright red")

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if player.TeamColor == teamWithTools then
            -- Your if statement that gives the tools
        end
    end)
end)

1 comment

0

Thank you!

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