Hello!
I am trying to make a defibliators but i got issues with reviving.
Server script:
revive.OnServerEvent:Connect(function(plr, target)
local hum = target:FindFirstChild("Humanoid")
if not target:FindFirstChild("Zombie") then
if hum.Health < 0.10 and target:FindFirstChild("Head") and not db then
db = true
local rag = target:FindFirstChild("Ragdoll")
rag.Value = false
hum.Health = 20
defibs.Hitbox.Revive.PlayOnRemove = true
for _,v in pairs(defibs.Parent:FindFirstChild("Humanoid"):GetPlayingAnimationTracks()) do
v:Stop()
end
defibs:Destroy()
wait(1.5)
db = false
end
end
end)
So, I have a sword that damages player, but cant damage when players healths are less 0.10
I recommend having a fake health, and that health is a value, if the health value is lower than or equal to 0, then the player is “dead” or knocked, there will be a countdown I am guessing for the reviving, and if that countdown is exceeded, then the player’s actual health gets damaged slowly, and at one point they have their actual health quickly reach 0, and if the other player revives them on time, their ragdoll stops, and they get their health value back to something higher than 0.
Let me explain, when the player joins, you do Player.Character, create a new instance, which is a number value. Make that number value 100, and then name it FakeHealth.
Make this sword sub duct a certain amount from the FakeHealth.Value instead of Humanoid.Health, the rest is self explanatory. If you are still lost, let me know.
For my case, I just use math.max between a player’s intended new health and 0.1. Frankly, this is a fairly specific issue to your game and you haven’t specified what about this isn’t working in the first place. Please remember to abide by the category guidelines. One of the highlighted questions to answer is:
R2DA wont allow damage below .1 hp.
To be certain no weapons break this rule, everyone who wana do any damage whatsoever needs to use the TakeDamage module.
Tip: For simplicity I also do _G.TakeDamage = require(path.TakeDamage)
so that you can just use _G.TakeDamage anywhere in any Script without requiring it.
Issue here is that your sword can damage beyond .1, it wont do any damage once your health is <.1 but if its at 10hp and you do 20hp damage your survivor will be set to Health = 0.
I recommend creating a TakeDamage module to obtain clarity.
@Sunx_x Can you do rag.Value = true without the humanoid dying?
I don’t know about the use of a module facilitating damage but if that fits your convention or system, that’s fine. An organised way to handle damage has its use cases, but I don’t think that’s quite required in this case. Simply clamping your health can avoid that death issue.
Define Humanoid as your character’s Humanoid and run. Set your health to 10 and call Humanoid:TakeDamage(20) or whatever you do to damage a Humanoid. Even do Humanoid:TakeDamage(100^100). Health will not be set to 0, getting rid of that concern you pitched below the block quote.