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

Giving certain teams different weapons?

I'm building a PVP and I want the red team to have a specific weapon, let's just call that weapon Weapon1 and I want the blue team to have another specific weapon, let's just call it Weapon2. How do I make it so I can give the players from both teams have their own weapon by moving the weapon from ReplicatedStorage?

1 answer

The script is as follows:

local ReplicatedHolder = game:GetService("ReplicatedStorage");
local TeamsHolder = game:GetService("Teams");

-- // Teams that can be found

local RedTeam = TeamsHolder:WaitForChild("Red Team");
local BlueTeam = TeamsHolder:WaitForChild("Blue Team");


-- // Weapons that are held in the ReplicatedStorage

local Weapon1 = ReplicatedHolder:WaitForChild("Weapon1");
local Weapon2 = ReplicatedHolder:WaitForChild("Weapon2");

-- // Events

game.Players.PlayerAdded:Connect(function(player)  -- Gives the weapon when the player joins the game.
	local Bp = player:WaitForChild("Backpack");
	print(player.Name .."'s Backpack has been loaded!");
	
	if player.Team.Name == "Blue Team" then
		local ClonedWeapon1 = Weapon1:Clone();
		ClonedWeapon1.Parent = Bp;
	end	
	
	if player.Team.Name == "Red Team" then
		local ClonedWeapon2 = Weapon2:Clone();
		ClonedWeapon2.Parent = Bp;
	end
	player.CharacterAdded:Connect(function(character) -- Gives the weapon when the player respawns in-game.
		local BackpackRespawn = player:WaitForChild("Backpack");
		
		if player.Team.Name == "Blue Team" then -- If the player's team is "Blue Team" then gives Weapon1, from ReplicatedStorage.
			local ClonedWeapon1 = Weapon1:Clone();
			ClonedWeapon1.Parent = BackpackRespawn;
		end
		
		if player.Team.Name == "Red Team" then -- If the player's team is "Red Team" then gives Weapon2, from ReplicatedStorage.
			local ClonedWeapon2 = Weapon2:Clone();
			ClonedWeapon2.Parent = BackpackRespawn;
		end
	end)	
end)

Tried to break it down in both :PlayerAdded() and :CharacterAdded() events. You basically give them a weapon once they join the game & later on you give them the weapon once they respawn depending on the team they are at.

Hope this helps you!

I'm aware that I have given you the whole script as a request, but hope you learn from it, check the Roblox:API more often!

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