Help with Assigning weapons to each team

So I want a Blue team(“Blue”) to receive blue color weapon (“X”) and Red team (“red”) to receive red weapon and blue team must not receive red weapon and vice versa

it would be a great help if you could give me the script and tell me where to put it

2 Likes

You mean team-only tools? :face_with_monocle:

You’re not really supposed to ask people to write scripts on here for you. However, I can explain it to you!

First check out documenation on Player.Team
Since it’s in reference to team color, check Player.TeamColor out as well.

Now for the explanation: You can simply do this by checking which team the player is on at the start of whatever event causes this (new round, etc.). Based on their team, clone a specific weapon (or group of weapons) into their Backpack.

Here’s the script: function teamFromColor(color)
for _,t in pairs(game:GetService(“Teams”):GetChildren()) do
if t.TeamColor==color then return t end
end
return nil
end

function onSpawned(plr)
local tools = teamFromColor(plr.TeamColor):GetChildren()
for _,c in pairs(tools) do
c:Clone().Parent = plr.Backpack
end
end

function onChanged(prop,plr)
if prop==“Character” then
onSpawned(plr)
end
end

function onAdded(plr)
plr.Changed:connect(function(prop)
onChanged(prop,plr)
end)
end

game.Players.PlayerAdded:connect(onAdded) . Place it in the server script service, if you want to assign a tool to a team, place the tool under the team.

yea
please i need 30 letters pls pls

Making a script isn’t needed at all. Just put the tools in the Team object.
image

function teamFromColor(color)
for _,t in pairs(game:GetService(“Teams”):GetChildren()) do
if t.TeamColor==color then return t end
end
return nil
end

function onSpawned(plr)
local tools = teamFromColor(plr.TeamColor):GetChildren()
for _,c in pairs(tools) do
c:Clone().Parent = plr.Backpack
end
end

function onChanged(prop,plr)
if prop==“Character” then
onSpawned(plr)
end
end

function onAdded(plr)
plr.Changed:connect(function(prop)
onChanged(prop,plr)
end)
end

game.Players.PlayerAdded:connect(onAdded) put it in serverscriptservice. Put your tool in the team.

Please don’t send the same script, just edit your last message. Also, use code blocks.

yes, sorry :grinning: :grinning:

its not working i will go with the script

Alright. I’ve made a little script for you.

local Teams = game:GetService("Teams") -- Gets the Teams service
local Blue_Tools = script.Blue -- Blue tools
local Red_Tools = script.Red -- Red tools

game.Players.PlayerAdded:Connect(function(Player) -- When a player joins
	Player.CharacterAdded:Connect(function(Character) -- When a player spawns
		if Player.Team == Teams.Blue then -- If the player is in the "Blue" team
			for i, v in ipairs(Blue_Tools:GetChildren()) do -- For everything in the "Blue" folder
				if v:IsA("Tool") then -- If an object is a tool
					v:Clone().Parent = Player.Backpack -- Clone the tool and paste it in the player's backpack
				end
			end
		elseif Player.Team == Teams.Red then -- If the player is in the "Red" team
			for i, v in ipairs(Red_Tools:GetChildren()) do -- For everything in the "Blue" folder
				if v:IsA("Tool") then -- If an object is a tool
					v:Clone().Parent = Player.Backpack -- Clone the tool and paste it in the player's backpack
				end
			end
		else  -- If the player is in another team
			warn("You're not in the Blue/Red team.")
		end
	end)
end)

Result:
I placed a tool called “Boombox” in the “Blue” folder and I’m in the blue team. Here is the result!

3 Likes