Making players invincible

So basically, I want to make my players invincible in the lobby but not when they go into the game. Currently I set a forcefield parent to the character when the player joins the game, using a player added event. The issue is, when they go into the arena, I destroy the forcefield, the players have 5 lives basically but when they die for the first time, I have a character removing event and inside that I destroy the new forcefield. But this character removing event runs before the character added event so I just get an error that’s saying the forcefield doesn’t exist. Is there any easier way of doing this?

2 Likes

If you want the player to be essentially immortal, you want to make their max health math.huge ← this means infinite. If you use explosions, then they’ll need a forcefield as well but the lobby wouldn’t be in the battlefield area usually, so there may be another way to make it where the explosions don’t hurt others.

2 Likes

Why are you destroying the forcefield in the CharacterRemoving event? If the ForceField’s is a descendant of the character, than it’ll be destroyed anyway. (It’s complicated, but kind of yes and kind of no)

2 Likes

you could try using a boolean variable to track whether the forcefield has been created or not. Set the variable to true in the player added event after creating the forcefield, and check its value before attempting to destroy the forcefield in the character removing event. This way, you ensure that the forcefield is only destroyed when it has been created. here is a example local forcefieldCreated = false

player.PlayerAdded:Connect(function(plr)
– Create forcefield here
forcefieldCreated = true
end)

player.CharacterRemoving:Connect(function(char)
if forcefieldCreated then
– Destroy forcefield here
end
end)

2 Likes

Could I add a character added event inside of the character removing event? So it adds it once the character is loaded back in

Yes, you can add a character added event inside the character removing event to ensure that the forcefield is added to the new character as soon as it is loaded. However, you need to make sure that the forcefield is only added once per player, not for every character added event. To do this, you can use the player’s PlayerGui property to check if the forcefield has already been added to the player’s previous character.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.