Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How come players in my game don't die when they reach 0 health?

Asked by 7 years ago

So, i am working on a game involving knives. Whenever i "kill" someone, they don't die, but they go to negative health. It's really frustrating. I even tried making a script that breaks joints when you reach 0 health, but that didn't work. Any help is appreciated. Thanks!

0
This sounds like you are using FE and have applied the damage in a local script which will not replicate to the server. If this is the case you need to take the damage on the server side so that the change will replicate. User#5423 17 — 7y
0
It's probably because of FE like he said^ but you could use :BreakJoints() as well Vulkarin 581 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Your problem could be in several factors.

  • You don't check the player's health correctly

  • You don't subtract the player's health correctly

How do you check if the player's health is less that 0? If your using

1if humanoid.Health == 0 then whatever end

then you are doing it wrong. You need

1if humanoid.Health <= 0 then whatever end

However, I doupt that this is your problem. Now, I bet you damage the players via the following method:

1humanoid.Health = humanoid.Health - 20 (or whatever the damage is) end

While this is not wrong, it is also possible to do it via the :TakeDamage() function. your script would look like this:

1local damage = 20 --How much damage the knife does
2humanoid:TakeDamage(damage)

Lastly, if all else fails, I have only one idea of what to do. Check it the player has <= 0 health, and then call the :LoadCharacter() function on their player (not character). Your script would look like this: (LocalScript inside StarterPlayerScripts)

01local player = game.Players.LocalPlayer
02 
03while true do wait(0.1)
04    if player.Character ~= nil then
05        local humanoid = player.Character:FindFirstChild('Humanoid')
06        if humanoid ~= nil then
07            if humanoid.Health <= 0 then
08                humanoid:TakeDamage(math.huge()) --Makes them take infinite damage. (Might not work in your case)
09                player:LoadCharacter() --Forces them to respawn
10            end
11        end
12    end
13end

Accept if helped thx

Ad

Answer this question