Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

0

You can try it out :Clone() !

0

Can you give me an answer instead? I never tried that property before

0

Use ":Clone()" and a "for i,v in pairs" loop, just define I how many seconds or do a wait('seconds here')

1 answer

✓ Accepted answer

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

2 comments

0

It still heals you even if Transparency is set to 1

0

Ok thats what I thought would happen, Im fixing it.

This discussion is preserved as it was. New answers, comments, and votes are closed.