Prevent Player from taking damage from weapon

Hey! I have ran into a problem with my gun system and need some help.

Problem: I am having trouble preventing a player’s health going anywhere below 15. The problem I had is that when a player is ragdolled (which players will ragdoll at 15 HP) and gets shot by a gun that deals more then 15 damage, their humanoid will die. How can I prevent this and cause the players health to not end up going to 0. I have used runservice loops to try to put the players health at 15 when they get ragdolled, but this seems to not have helped.

Yes guns have checks on them for if the players health is at 15 or below 15 but the player regenerates and the checks become useless.

Any solutions?

1 Like

can you send a snippet of the script

1 Like

Which script are you wanting to see a snippet of?

1 Like

Can we see the script with the checks?

the event with checks for damage

image

Attempts to prevent revive health to 15 if it goes below 15.

no you shouldnt put the check as a seperate script, instead you should edit the damage event for the gun to check if total damage - hum.health is less than 15

1 Like

I don’t exactly understand what you’re saying.

Are you saying I should use a for loop and take damage until the players health goes to 15 or goes below?

I believe he means to use a total sum of the humanoid’s health minus the damage dealt by the gun (or the other way round) is less than 15, so to immediately act and revive the player likely before they can die, like:

if damage - humanoid.Health < 15 then
humanoid.Health = 15
end

I did some testing and it worked.

1 Like

Yes but the problem with this is, lets say the persons health is 16 and a gun does 20 damage. The guns hit wont register and the player wont get ragdolled. I tried something out using something similar aka a for loop and it works now. It will take loop until the health is 15 or reaches the damage number

1 Like

I see, but what if you were to do something like this:

humanoid.MaxHealth = humanoid.Health + damage
humanoid.Health = humanoid.MaxHealth
humanoid:TakeDamage(damage)
humanoid.MaxHealth  = --default max health
if humanoid.Health < 15 then
humanoid.Health = 15
end

Rendering them able to take the punch, then being slapped down to their original health and then being ragdolled?

Just proposing a different method, as a for loop seems to be more of a cluttered method than neccessary in my opinion.

I trying to do this with a FE Gun Kit. But there no tutorial on this, and I try to make the damage like -20, but it didn’t work.