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

Humanoid respawn with more health?

Asked by 4 years ago

hello, im pretty new to building, but im trying to make this game. i want to make a NPC or Zombies respawn with more health. for example, it'll have a MaxHealth of 100, and then on its cloning function come back with a MaxHealth of 200. I've tried this:

name="Humanoid"

robo=script.Parent:clone()

while true do
    wait(1)
    if script.Parent.Humanoid.Health<1 then
        robot.humanoid.maxhealth = robot.humanoid.maxhealth + 100
        robot.humanoid.maxhealth = robot.humanoid.health + 100
        robot=robo:clone()
        robot.Parent=script.Parent.Parent
        robot:makeJoints()
        script.Parent:remove()
    end
end

but it doesnt seem to work. any ideas on what i can do?

2 answers

Log in to vote
0
Answered by 4 years ago

Try this:

name="Humanoid"

robo=script.Parent:clone()

script.Parent.Humanoid.Died:connect(function()
--Your code
end)
0
ok cool! i got it to work. what u said gave me this idea: nick2222 20 — 4y
0
~~~~~~~~~~~~~~~~~ local clone = script.Parent:Clone() Function:Died() clone.Parent = workspace clone.Humanoid.MaxHealth = clone.Humanoid.MaxHealth +100 clone.Humanoid.Health = clone.Humanoid.Health +100 ~~~~~~~~~~~~~~~~~ nick2222 20 — 4y
0
It would be nice if you accept this answer :D itz_rennox 412 — 4y
0
I'd be more than happy to. how do i do that? this is legit my first time on this website LOL nick2222 20 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

heres the answer/code if anyone else wants it(edit, this one worked a bit better)

local myHuman = script.Parent:WaitForChild("Humanoid")
local clone = script.Parent:Clone()

function died()
    clone.Humanoid.MaxHealth = clone.Humanoid.MaxHealth +100
    clone.Humanoid.Health = clone.Humanoid.Health +100
    wait(5)
    clone.Parent = workspace
    clone.Humanoid.MaxHealth = clone.Humanoid.MaxHealth +100
    clone.Humanoid.Health = clone.Humanoid.Health +100
    game:GetService("Debris"):AddItem(script.Parent,0.1)--this probably isnt needed but i have it in my scripting
end

myHuman.Died:Connect(died) --
0
*Humanoid.Died itz_rennox 412 — 4y

Answer this question