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

How can I make a respawning health kit? (meaning how can I make the object respawn)

Asked by 4 years ago
Edited 4 years ago

I have made a health kit script and I inserted it into a part for the player to heal but the problem is how can I make it respawn every 20 or 30 seconds after the player touches it to heal? please help.

function onTouched(part)
 local h = part.Parent:findFirstChild("Humanoid") -- It finds Humanoids in whoever touched this
 if (h ~=nil) then -- If there is a Humanoid then
       h.Health = h.MaxHealth -- Sets the health to maximum (full healing)
 end
 end

script.Parent.Touched:connect(onTouched)

Note: This is a script not a local script

0
You can try it out :Clone() ! Xapelize 2658 — 4y
0
Can you give me an answer instead? I never tried that property before Simpletton 82 — 4y
0
Use ":Clone()" and a "for i,v in pairs" loop, just define I how many seconds or do a wait('seconds here') jordysboy 53 — 4y

1 answer

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

If you set the parent to nil its the same as deleting it, but the part is still in the game technically. Then you can pull it back into the workspace, making it appear again.

function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h ~=nil) then
        h.Health = h.MaxHealth
        script.Parent.transparency = 1
        local Parent = script.Parent.Parent
        script.parent.parent = nil
        wait(math.random(20, 30))
        script.Parent.Parent = Parent
    end
 end

script.Parent.Touched:connect(onTouched)

Something like that

0
It still heals you even if Transparency is set to 1 Simpletton 82 — 4y
0
Ok thats what I thought would happen, Im fixing it. Benbebop 1049 — 4y
Ad

Answer this question