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

How to Get a Tool Equipped Based on Team?

Hello, I have the following script.

function giveWeapon(part)
	if part:GetChildren("Humanoid") then
		if part.TeamColor == "Really blue" then
			local BlueLaserGun = game.Workspace.BlueLaserGun:Clone()
			BlueLaserGun.Parent = game.StarterPack
		end
		if part.TeamColor == "Really red" then
			local RedLaserGun = game.Workspace.RedLaserGun:Clone()
			RedLaserGun.Parent = game.StarterPack
		end
	end
end
script.Parent.Touched:connect(giveWeapon)

Now, this is inserted in a part and whenever I touch it, even though there are established teams, I get the error saying that TeamColor isn't a valid member of part. The Blue and Red LaserGuns do exist in Workspace. Can someone tell me why this isn't working? I would really appreciate it.

1 comment

0

It's cause inside that part their is no 'TeamColor' hold on a sec

2 answers

✓ Accepted answer

So your problem was that a part does not have a teamcolor, so let's fix that.

function giveWeapon(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player ~= nil then
		if player.TeamColor == BrickColor.new("Really blue") then
           		local BlueLaserGun = game.Workspace.BlueLaserGun:Clone()
            		BlueLaserGun.Parent = game.StarterPack
        	elseif player.TeamColor == BrickColor.new("Really red") then
            		local RedLaserGun = game.Workspace.RedLaserGun:Clone()
            		RedLaserGun.Parent = game.StarterPack
		end
	end
end

script.Parent.Touched:connect(giveWeapon)

So what I did was got the 'Player', which Player is the object that has the TeamColor, while you were looking for TeamColor inside the 'Character'. Hope this helped.

If this doesn't work, then reply back or edit your question with the error and I'll go back and see what I missed.

EDIT I editted line 4 and 7 to include BrickColor.new(), as the colors are a brickcolor. Script should work now.

  • NinjoOnline

6 comments

0

Team Colors are BrickColor values, might want to show that on line 4 and 7

0

Hi... it still isn't working, but I'm going to try inserting .BrickColor in various places, see where it works... but I'm going to keep trying, and that's it, I guess.

0

Oh yeah, I spotted the problem, as M39a9am3R said, lines 4 and 7 have been editted so it will work now

0

Hmm... still not working, but it is being cloned into the StarterPack. I just can't see it in my toolbar when I play. Also, I added a print for testing purposes, and it is detecting which team I am on, but it isn't letting me use the tools which are in starterpack.

0

I have actually just found out what it is... I was putting the tool in starterpack, not backpack. Duh. slams head on table Well, thanks for all the help!

0

Oh yeah :P I should have spotted that XD

function giveWeapon(part)
    if part.Parent.Humanoid then
        if part.TeamColor == BrickColor.new("Really blue") then
            local BlueLaserGun = game.Workspace.BlueLaserGun:Clone()
            BlueLaserGun.Parent = game.StarterPack
        end
        if part.TeamColor == BrickColor.new("Really red") then
            local RedLaserGun = game.Workspace.RedLaserGun:Clone()
            RedLaserGun.Parent = game.StarterPack
        end
    end
end
script.Parent.Touched:connect(giveWeapon)

1 comment

0

thumbs down... for what

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