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.
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.
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)