Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Part.Touched is not working? everything look fine

Asked by 3 years ago
Edited 3 years ago

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
0
well what do u want to make WesleyAng_3 153 — 3y
0
Make sure you actually touch the part. Also make sure receptor.CanTouch = true. imKirda 4491 — 3y
0
@imKirda CanCollide doesn't need to be enabled or disabled. Dovydas1118 1495 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

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. 1ofm12ck53 75 — 3y
Ad

Answer this question