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

Why Doesn't The Script Print Detected When Part Is Hit?

Asked by 6 years ago

The Purpose Of This Script is to detect if a part (The Part Is The Parent Of The Script) touches another part named "SauceDetector". The Part "SauceDetector" is an unanchored, can collide off part the falls from right above the Part and touches the part. For some reason the Print("SauceDetected") Doesn't Print.

function onTouched(hit)
if hit.Parent.Name == "SauceDetector" then
    print("SauceDetected")
script.Parent.Sauce.Value = true
end
if hit.Parent.Name == "CheeseDetector" then
script.Parent.Cheese.Value = true
end
if hit.Parent.Name == "PepperoniDetector" then
script.Parent.Pepperoni.Value = true
end
if hit.Parent.Name == "MushroomDetector" then
script.Parent.Mushroom.Value = true
end
end
script.Parent.Touched:connect(onTouched)

If You Know Why Its Not Detecting Please Let Me Know!

1 answer

Log in to vote
3
Answered by 6 years ago

I think it's not printing as you say "hit.Parent.Name" which I think is the workspace.

To fix this, instead of putting hit.Parent.Name, say hit.Name in each of them.

1
Hit.Parent.Name should return the Handle of your Character; username Ziffixture 6913 — 6y
1
So you're correct, he's asking if the Username is equal to "SauceDetector", which will never be true, unless someone is that random Ziffixture 6913 — 6y
0
@Ihatecars100, I tried changing hit.Parent.Name to hit.Name and it didn't work :/ Also @simplealgorithm, I'm trying to Print("SauceDetector") if the Part touches a Part Named SauceDetector, Not A Player. kizi3000 88 — 6y
0
@kizi3000 maybe try changing :connect() to :Connect()? ihatecars100 502 — 6y
View all comments (2 more)
0
still doesn't work :/ kizi3000 88 — 6y
0
are you definitely sure the part that's hitting is called "SauceDetector?" ihatecars100 502 — 6y
Ad

Answer this question