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

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

Asked by
hokyboy 270 Moderation Voter
5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

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)
0
That won't work, TeamColor isn't a function User#19524 175 — 5y
0
oh i will edit it see it works DontGetTired255 6 — 5y
0
does this works DontGetTired255 6 — 5y

Answer this question