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

When I touched, it takes away all health?

When I touched the oart that is located in script.Parent, it takes away all health. I want it to take away half.

Text = "You have gotten health taken away."

function Touched(hit) --"Touched" is name of the function.

    local hum = hit.Parent:findFirstChild("Humanoid")

    if hum then
        hum.Health = hum.Health - (hum.Health/2) --subtracts half the health, this won't ever kill the player though

		print(Text)
    end
end

script.Parent.Touched:connect(Touched)



1 answer

✓ Accepted answer

Why don't you do this:

Text = "You have gotten health taken away."
ting = 0
function Touched(hit)

    local hum = hit.Parent:findFirstChild("Humanoid")

    if hum then
	if ting == 0 then
	ting = 1
        hum.Health = hum.Health -50 --subtracts 50 health from him
        print(Text)
		wait(1)
		ting = 0
    	end
	end
end

script.Parent.Touched:connect(Touched)

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