Making a player unable to take damage

How could I make a player unable to take any form of damage?
I am currently trying to make a sort of safezone for players, and I want them to not be able to take any damage while inside the safezone. I already know how to detect when players are in the safezone. I only need to figure out how to make the player invincible. I do not want to change the player’s health to a higher amount to make them “invincible”.

5 Likes

In your script that deals damage, check if the player is in a safe zone since you already know how, and then ignore the damage.

2 Likes

Another method would be to give a forcefield when they are in the safe zone.

2 Likes

But then the forcefield would be visible won’t it? Also I can’t use your first method because I want to do this in a separate script, and also there are many scripts that deal damage.

2 Likes

In my time I had an almost similar problem, the solution I came to was, in which the player has a boolValue called Safe, and check in the same damage script if the boolvalue is true, if it is true it will not do damage and if it is false it will hurt. You can apply my same method.

2 Likes

Another method is to check if they are in a safezone and always set their health to the max

if playerisinsafezone then
     while wait(.1) do
          Humanoid.Health = Humanoid.MaxHealth
     end
end

This code will wait if the player is in a safezone and constantly set their health to the max health of the player.

3 Likes

There are many different damage scripts, and I don’t want to do this for all of them, is there any way to just stop them from taking damage?

2 Likes

He said he can’t do this method because he has too much damage scripts.

1 Like

Good idea, but I have a healthbar in the bottom left of the screen, so it would be blatantly obvious that the player is still taking damage and getting regenerated.

1 Like

Then for a safezone you can either make the health bar gui invisible or just have a static image of a full health visible so it looks like they are taking no damage.

1 Like

Yeah but that’s a hacky method. Is there any way to just completely stop the player from taking damage?

3 Likes

From what I know, there is no way unless you modify the damaging scripts itself.

1 Like

ok what if I was trying to make a forcefield (I need a forcefield and a safezone lol) what would I do, since I cant change the players health value or it will affect the healthbar? Also I want it to be a custom forcefield so I don’t want to use roblox’s forcefield

2 Likes

Roblox has a built in forcefield that you can use. Read the article below.
https://create.roblox.com/docs/reference/engine/classes/ForceField

1 Like

I said I wanted to make a custom forcefield.

I just edited this method and did something similar to it. Thanks!

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