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

how to define a team color in a humaniod touched script?

local Brick = script.Parent

local function PlayerTouched(Part) if game.Player.Localplayer--- how to see in what team color he is that the only thing i need this for capture points end end

Brick.Touched:connect(PlayerTouched)

2 answers

✓ Accepted answer

###You can get the player in a server script with the GetPlayerFromCharacter method of the Players service. LocalPlayer is nil on the server. We will get the touching part's Parent, which will hopefully be the player's character and not some random model or the workspace.

local Players = game:GetService("Players")
local Brick = script.Parent
local getPlayerFromCharacter

getPlayerFromCharacter = function(model)
    return Players:GetPlayerFromCharacter(model)
end

local function PlayerTouched(part)
    local plr = getPlayerFromCharacter(part.Parent)

    if plr then
        plr.TeamColor = BrickColor.new("Bright blue") -- just an example
    end
end

Brick.Touched:Connect(PlayerTouched)

If you want to be a brick touched to be a team there is the script:

local Brick = script.Parent

local function PlayerTouched() 
    game.Players.LocalPlayer.TeamColor = BrickColor.new("Institutional white")
end

Brick.Touched:Connect(PlayerTouched)

3 comments

0

That won't work, TeamColor isn't a function

0

oh i will edit it see it works

0

does this works

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