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

Team Tool Giver. Not working???

Description of what I need it to do: In my game, you start off in the lobby, which has its own team that is Medium stone grey. After a while the players in the lobby change to either red or blue randomly. Then they teleport to the map with random spawns. I have them spawning on givers... to give them they necessary tools they need, but there are some occasions to where they wouldn't receive the tools. TO THE POINT: The script is being copied from server storage and pasted into workspace at the approximate time I need the players to receive their tools. The script needs to recognize players already in the game/ on the red and blue team and give them the tools. Instead of using a lousy button giver...

Here is the script:

weapons = {game.ServerStorage.Knife:Clone(), game.ServerStorage.Pistol:Clone(), game.ServerStorage.Sniper:Clone()}
	 
	for _, v in pairs(game.Players:GetChildren()) do
	    if v.TeamColor == BrickColor.Red then
	    weapons[1].Parent = v.Backpack
	end
	        if v.TeamColor == BrickColor.Blue then
	        weapons[math.random(1,2)].Parent = v.Backpack
	        end
	    end
	
	wait(3)
script:Destroy()

Notice: Before attempting to fix it read description above script (Entirely)

2 comments

0

what's the parent of the script?

0

Workspace

1 answer

✓ Accepted answer

If its a server script and the parent of the script is workspace then your code will be:

wait(3)
for _, player in pairs(game.Players:GetChildren()) do
	weapons = {game.ServerStorage.Knife:Clone(), game.ServerStorage.Pistol:Clone(), game.ServerStorage.Sniper:Clone()}
	
	if player.TeamColor == BrickColor.Red then
		weapons[1].Parent = player.Backpack
	end
	if player.TeamColor == BrickColor.Blue then
		weapons[math.random(2, 3)].Parent = player.Backpack
	end
end
wait(3)
script:Destroy()

if its in a localscript and its on the backpack your code will be:

local player = game.Players.LocalPlayer


spawn(function()
	local weapons = {game.ServerStorage.Knife:Clone(), game.ServerStorage.Pistol:Clone(), game.ServerStorage.Sniper:Clone()}
	
	if player.TeamColor == BrickColor.Red then
		weapons[1].Parent = player.Backpack
	end
	if player.TeamColor == BrickColor.Blue then
		weapons[math.random(2, 3)].Parent = player.Backpack
	end
	wait(3)
	script:Destroy()
end)

2 comments

0

Thank you I will check it out as soon as i get a chance

0

You're welcome !

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