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

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

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

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)

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