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

I created a medkit script, but when i have 100 health it destroy's itself anyway. anyway to fix it?

here's the code.

local sound = game.Workspace.soundplayer.sound3

function onTouched(hit)
	local h = hit.Parent:findFirstChild("Humanoid")
if h.health >= 100 then
	local h = hit.Parent:findFirstChild("Humanoid")
	print("Max Health!")
end 
if h.Health < 100 then
	local h = hit.Parent:findFirstChild("Humanoid")
	h.Health = h.Health + 1
	sound:Play()
	script.Parent:Destroy()
end

if h.Health >=80 then
	local h = hit.Parent:findFirstChild("Humanoid")
	h.Health = 100
	sound:Play()
	script.Parent:Destroy()
end

    



end
script.Parent.Touched:connect(onTouched)

2 comments

0

.

0

.

1 answer

✓ Accepted answer
local sound = game.Workspace.soundplayer.sound3

function onTouched(hit)
    local h = hit.Parent:findFirstChild("Humanoid")
if h.health >= 100 then
    local h = hit.Parent:findFirstChild("Humanoid")
    print("Max Health!")
end 
elseif h.Health < 99 then
    local h = hit.Parent:findFirstChild("Humanoid")
    h.Health = h.Health + 1
    sound:Play()
    script.Parent:Destroy()
end

elseif h.Health >=80 then
    local h = hit.Parent:findFirstChild("Humanoid")
    h.Health = 100
    sound:Play()
    script.Parent:Destroy()
end





end
script.Parent.Touched:connect(onTouched)

This should work.

8 comments

0

it worked. Thanks Alot!

0

Please accept!

0

How do i accept? i'm fairly new to the website.

0

Under the comments it should say accept answer.

0

Can't Find it.

0

You know where is says report underneath the answer? Beside that is where it should be.

0

I see report but i don't see an "accept answer"

0

Nevermind, Just had to change my browser.

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