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

Healing script lasts forever and heals too much, what wrong?

So i have two problems:

  1. My character is supposed to heal 10 health per second, but instead he heals like 50 health per milisecond.

  2. the healing lasts forever, no matter if i am touching the healing brick or not. the only way to stop it is to die.

heres the script:

function OnTouched (person)
	local i = person.Parent:FindFirstChild("Humanoid")
	if i ~= nil then
		while i ~= nil do
			wait(1)
			i.Health = i.Health + 10
		end
	end
end

script.Parent.Touched:Connect(OnTouched)

2 comments

0

add a debounce

0

how exactly?

1 answer

✓ Accepted answer

add a debounce

local deb = true
local active = true
function OnTouched (person)
	if active = true then
		active = false
		if deb == true then
			deb = false
			local i = person.Parent:FindFirstChild("Humanoid")
			if i ~= nil then	      
				
				
				i.Health = i.Health + 10
					
			end
		wait(1)
		deb = true
		end
	end
end

function touchended()
active = true
end
	 
	script.Parent.Touched:Connect(OnTouched)
	script.Parent.TouchEnded:Connect(touchended)

i havent tested this , because im too lazy to , if someone can take over , ... ok

3 comments

0

you need to walk around the part tho , it sucks , but i dont have enough time to think

0

if my guess is right plz upvote , if not , ... k

0

this works!

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