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 check if player touching part continuously?

Typical script like this:

local debounce = false 

function onTouch(part)

local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false then
debounce = true

human.Health = human.Health - 30 

wait(1) 
debounce = false
end 
end 

script.Parent.Touched:connect(onTouch)

But if player doesn't move, he will not recieve damage, how to change this?

1 comment

0

Try to remove the debounce.

1 answer

✓ Accepted answer

You can use part.TouchEnded, like this:

local touching = false

function onTouch(part)
	touching = true
	
	repeat --I didn't use while loop because that would run whenever the touching is true, but the repeat breaks when the touching is false, and won't run until its called again
		
		--Put the code here that you continuously want to run while the player is touching the part
		
	until touching == false
		
	
end)

function onTouchEnded(part)
	
	touching = false
	--Put the code here that you want to run when the player is not touching the part anymore	

end)

script.Parent.Touched:Connect(onTouch)
script.Parent.TouchEnded:Connect(onTouchEnded)

Combine this with your code and let me know if I helped

1 comment

0

Thank you very much! You helped me a lot! I thought about this onTouchEnded thingy, but didn't think about repeat loop. Thanks!!!

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