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

Why Part.Touched is not working? everything look fine

Script:

print("a")
receptor.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		print("b")
		Eaten(receptor,hit)
	end
end)
print("c")

Output:

a
c

3 comments

0

well what do u want to make

0

Make sure you actually touch the part. Also make sure receptor.CanTouch = true.

0

@imKirda CanCollide doesn't need to be enabled or disabled.

1 answer

If you're expecting Touched to pass right off the bat and the output to have a, b, and c consecutively, this will never happen with the code you have. Touched is an RBXScriptSignal and will only run the code within a connected function if it successfully fires. It does not behave like an if statement nor does it behave like a loop.

With that being said, your output will ALWAYS look like this:

a
c
b
... -- other b's

Do you want the if to fire immediately after a is printed? You can put the print("c") after the print("b") to achieve an output of a, b, and c consecutively, respectively. If you don't, you're stuck with a, c, and then any b's for your output unless you put all 3 prints inside of the function.

1 comment

0

I tried put print("b") outside if statement but that still doesn't work. There is no "b" in the output. why? At least it touch baseplate.

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