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

How would you make this so when you're on a certain team, it removes your forcefield?

Asked by 9 years ago

I have a script that gives you a forcefield when you join, but I'd like it so when you change to a certain team, the forcefield is removed, but changing to another certain team brings it back.

function playerRespawn(newPlayer)
    wait()
    local ff = Instance.new("ForceField", newPlayer.Character)
end

game.Players.PlayerAdded:connect(function(newPlayer)
    newPlayer.Changed:connect(function(set)
        if (set == "Character") then
            playerRespawn(newPlayer)
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
Froast 5
9 years ago
local ffTeamColor = BrickColor.new(0)

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if player.TeamColor == ffTeamColor then
            Instance.new('ForceField', character)
        end
        player.Changed:connect(function(property)
            if property == 'TeamColor' then
                if player[property] == ffTeamColor then
                    Instance.new('ForceField',(player.Character and player.Character))
                elseif player.Character and player.Character:FindFirstChild'ForceField'
                    player.Character:FindFirstChild'ForceField':Destroy()
                end
            end 
        end)
    end)
end)
Ad

Answer this question