I am currently trying to code the death system for my game. I want it so that when the player dies, nothing is changed besides their move speed, jump power, and animations. I have tried editing the animations local script but it disabled all animations. Here is the script to change the player upon the state change:
local Player = script.Parent
local Value = script.Parent.Value
table.insert(_G.AlivePlyrs, Player)
print(_G.AlivePlyrs)
Value:GetPropertyChangedSignal("Value"):Connect(function()
if Value.Value == 1 then
local pos = table.find(_G.AlivePlyrs, Player)
table.remove(_G.AlivePlyrs, pos)
print(_G.AlivePlyrs)
else
if Value.Value == 0 then
table.insert(_G.AlivePlyrs, Player)
print(_G.AlivePlyrs)
end
end
end)
Here is my script to detect when the player dies:
local debounce = false
local inf = true
game.Players.PlayerAdded:connect(function(player)
task.wait()
if player then
repeat
task.wait(1)
debounce = true
if player.Character.Humanoid.Health < .01 then
player.Character.Value.Value = 1
end
debounce = false
until inf == false
end
end)
AlivePlyrs is a global because I need to use it in other scripts. The value is a number value rather than a bool value because the player can have more than 2 states.
i got you
im just changing the walkanim
its r6
but it works with r15 i hope
game.Players.PlayerAdded:Connect(function(plr) -- added player
local Deaths = Instance.new("NumberValue", plr) -- creates death value in player
Deaths.Value = 0 -- sets deathvalue to 0
Deaths.Name = "Deaths" -- changes the name of the death value
plr.CharacterAdded:Connect(function(chr) -- when character is added
local hum = chr:FindFirstChildOfClass("Humanoid") -- gets characters humanoid
local animate = chr:FindFirstChild("Animate") -- gets characters animate
if Deaths.Value >= 1 then
hum.JumpHeight = 20 -- change what you want and also if game set to JumpPower then change to that
hum.WalkSpeed = 20 -- change what you want
animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=180426354" -- change what your id is
end
hum.Died:Connect(function() -- died function
Deaths.Value = Deaths.Value + 1 -- changes deaths
end)
end)
end)
The issue with this is that a player with a 0 for the value is alive, a player with a 1 for the value is dying but can be saved and a player with a 2 for the value is going to be spectating. I need to change between them whenever needed. When the value is changed to 1, the player should still be in the same place too. The animations also are an idle and walk.
Oh, in that case, try programming it to prevent you from dying and instead leave you at 1 health (or whatever HP you would like). when an attack would have killed you normally. That way, you are not technically “dead” according to Roblox, and can still mess with it however you like.
EDIT: “Technically dead” here just refers to what Roblox would consider dead: <=0 HP
And of course, when you get hit a second time while in a “injured state”, you die instead of having your health set to anything >0
I changed it so the player doesn’t die from the monsters if they have too little hp and the animation plays. This is just about exactly what I wanted. I plan the player to have a timer to get revived withing or else they truly die so this is what I wanted.
Oh and also, one small note: depending on how low your “threshold” is, it’s possible that some enemies which deal low damage (usually tick based systems) can bypass this threshold and kill you instead of leaving you weakened. That is, if you never add tick-based damage systems or just enemies with very low damage, this is not an issue.
To counter this, you could add a check to the hitbox system where before damage is dealt, it checks if the damage dealt would kill the user, if so it puts them into the injured state, otherwise damage is just dealt
If your threshold is lower than 5 that should not be an issue. The warning was simply considering the possibility of enemies dealing damage lower than the threshold.