Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I find a player's team, can you help me?

Asked by 8 years ago

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


0
if player.TeamColor==BrickColor.new('Bright red') then ConnorVIII 448 — 8y
0
Please wait while I explain the answer in full detail. Reshiram110 147 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

What's the problem?

  • The debounce is unnecessary if you're using it this way
  • Touched returns the part, not the player
  • The team property is not called Team, it's called TeamColor
  • TeamColor isn't a string value, it's a BrickColor value
  • "Red" isn't a color. Use BrickColor.Red() or "Bright red" instead

Getting the player from a part

You can use a function of Players1. 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

TeamColor

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.


Comparing BrickColors

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.


Final Product

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!


  1. Players service, not the player object 

  2. The chart for converting brickcolor values is here 

0
RIP you posted while I was typing the answer lol Reshiram110 147 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

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!

0
That code is disgusting. Please tab it. AZDev 590 — 8y
0
Un-needed comment. Reshiram110 147 — 8y

Answer this question