Hello, i'm making a capture point script and I wan't to change the brickcolor to red if Red team captures the point, but it's not working.. can you help me?
local CapturePointA = game.Workspace.CapturePointA function Touched(player) debounce = false if player.Team == "Red" then print 'Red person gross' end end CapturePointA.Touched:connect(Touched) debounce = false
You can use a function of Players
1. You have to have the character as one of the parameters and it'll find the player that way.
--Wiki example local character = game.Workspace.Player local player = game.Players:GetPlayerFromCharacter(character) if player then print("Player is " .. player.Name) else print("Player doesn't exist!") end
The property name is TeamColor
. Not Team, and roblox is very sensitive to caps and small typos. Make sure you read through and fix all of them.
BrickColors
are they're own datatype and is a type of color value. They must either be compared to another BrickColor value or they can be turned into other values2.
print(BrickColor.new() == 3) print(BrickColor.new() == BrickColor.new()) print(BrickColor.White() == 0)
false
true
false
Use words such as "Name" or "Number" or "Color" to convert BrickColor to other values.
local CapturePointA = game.Workspace.CapturePointA function Touched(part) local player = game:GetService("Players"):GetPlayerFromCharacter(part.Parent) if player and player.TeamColor.Name == "Bright red" then --Checked to make sure the player existed; converted the BrickColor to a string using "Name" so we can compare the values print 'Red person gross' end end CapturePointA.Touched:connect(Touched)
Hope it helps!
Hello.
The reason why this script wasn't working was because 'Team' is not a valid member of the Player object. Also,you never added code that gets the player object from the character that touches the brick.
The fixed code is detailed below.
script.Parent.Touched:connect(function(h) --'h' is assigned to the object that touches the brick. local Player=game.Players:GetPlayerFromCharacter(h.Parent) --We are getting the player from the character that hit the brick.We use 'h.Parent' because the Player's leg or arm will hit the brick. if Player~=nil then --Checking to see if it was indeed a player that hit the brick. if Player.TeamColor==BrickColor.new('Bright red') then --Checking to see if the player is in the red team. print("EW A RED PERSON! GROSS!") --Yea,it is gross. end end end)
If this is the answer you were looking for,upvote it and mark it as the answer!