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?
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.
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)
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)
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.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.