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

Help with testing if a player is always touching a block?

Hi everyone,

I wanted to find out how to test if a player is always touching a block? I am making a terminal script

SCRIPT /


function onTouch(part)

script.Parent.Parent.Screen.SurfaceGui.Bar.Progress.True.Value = true
			
			end

while wait(1) do
script.Parent.Touched:connect(onTouch)

end

How would I do that?

1 answer

✓ Accepted answer

You need to make a while loop checking if the parent "Humanoid" exists, something like this:

function onTouch(part)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	while humanoid do -- While the humanoid exists do....
		script.Parent.Parent.Screen.SurfaceGui.Bar.Progress.True.Value = true
		wait(1) -- We wait 1 second before progressing again the bar
	end
end

script.Parent.Touched:connect(onTouch)

6 comments

0

Still doesn't work? I Am not sure why

0

try to remove "while humanoid do wait(1) end"

0

I mean, it works by itself, but it still counts down even when the player isn't touching it.

0

add an if statement to check if the humanoid still exists

0

Ok, all I have done is made it a click detector

0

lolwat? Touched and ClickDetector doesn't make any sense anyway if it works so hold the ClickDetector

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