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

How would I fix this script to make a player switch teams when they hit a block?

Asked by 9 years ago
local part = script.Parent
part.Touched:connect(function(hit)
    if hit.Parent then
        local hum = hit.Parent:FindFirstChild("Humanoid")
        if hum then
            local player = game.Players:GetPlayerFromCharacter(hum)
                player.Parent.TeamColor = BrickColor.palette("Fossil")
        end
    end
end)

Title is self-explanatory.

1 answer

Log in to vote
1
Answered by
Potlon 35
9 years ago

Here you go

local part = script.Parent

part.Touched:connect(function(hit)
    local parent = hit.Parent --the part that touched parent
    if game.Players:GetPlayerFromCharacter(parent) then --If player
        local player = game.Players:FindFirstChild(parent.Name)--Finds player
        player.TeamColor = BrickColor.new("Fossil")--Team color
    end
end)
Ad

Answer this question