Cutting to the chase:
My game is meant to have a gui for when you "die" (Which is depicted as DOWNED in the game), Your character doesn't die, instead, it just stays completely frozen on the ground, with a Gui allowing you to go back to the spawn, respawn or get back up.
The issue I'm having is that, when you reset character, the DOWNING works, but when players kill you with bullets in the PVP areas of the game, your character WILL die, the DOWN gui appears, but your character breaks and dies.
What I speculate is that the script gets you hurt OVER 0 HP, Therefore, it makes the game go crazy and kill you anyways.
This is the script for the bullet's damage, which is on each bullet's script.
damage = false
loops = 0
local TotalDamage = 15
Players = game:GetService("Players")
script.Parent.Touched:Connect(function(damaged)
local Playermanboi = Players:GetPlayerFromCharacter(damaged.Parent)
if damage == false then
local Humanoid = damaged.Parent:FindFirstChild("Humanoid")
if Humanoid == nil then return end
if damaged.Parent.Name == script.Parent.Name then return end
damage = true
if damaged.Name == "Shield" then
TotalDamage = TotalDamage / 3
end
if damaged.Name == "HumanoidRootPart" then return end
Humanoid.Health = Humanoid.Health - TotalDamage
wait(2)
damage = false
end
end)
And this is the script for the HumanoidStateType set to false, which is on StarterPlayerScripts
Plr = game.Players.LocalPlayer
Plr.CharacterAdded:Connect(function(char)
local Hum = char:WaitForChild("Humanoid")
Hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
local DeathAnim = Hum:LoadAnimation(char.Defeat)
Hum.HealthChanged:Connect(function()
if Hum.Health <= 0 then
DeathAnim:Play()
Hum.WalkSpeed = 0
Plr.PlayerGui.DownedGui.Enabled = true
Hum.HealthChanged:Connect(function()
if Hum.Health > 0 then
DeathAnim:Stop()
DeathAnim:Destroy()
Hum.WalkSpeed = 16
end
end)
end
end)
end)

5 comments
make a second debounce to prevent the damage from going below 0
Oh, how-so?
if Hum.Health == 0 then return end
Err, that's not the issue, the issue is that, let's say, your character has 19 HP, Then it gets hit by a 20 HP move, you get -1 HP.
HumanoidStateType.Dead should be set on the client and server both, because the respawn happens on the server but the character breaking happens on the client