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

How can I make a block to a color when a player steps on it?

Asked by 7 years ago

How can I make it so when a player that is on a team steps on a block and then it changes color? Ex: Player on red team steps on a block, it turns red. Here is what I have right now:

function Change(hit)
    local h=hit.Parent:FindFirstChild("Humanoid")
    if h~=nil then
        script.Parent.BrickColor = BrickColor.new("Team color")
    end
end

script.Parent.Touched:connect(Change)

1 answer

Log in to vote
0
Answered by 7 years ago

Here is my script that works:

local part = script.Parent --defines the variable "part"
part.Touched:connect(function(hit) -- do stuff when "part" is touched
    if hit.Parent:FindFirstChild("Humanoid") then -- if the thing that part is touching has a humanoid then (pretty much detects if it's a player)
        local player = game.Players:FindFirstChild(hit.Parent.Name) -- defines the variable, "player" as the player that touched the part
        part.BrickColor = player.TeamColor -- changes brickcolor to the player's teamcolor
    end
end)
0
Thanks! MrWafflesNBacon -1 — 7y
Ad

Answer this question