Are you suppose to expect the print statement to print out Work? If that’s the case, you put it in the else statement, which never works until there is no humanoid touching the part.
No. Im trying to get the print statement to NOT print work when I touch the part, and only when another part touches it. But for some reason it prints if anything is touching the part.
local Part = script.Parent
function WhenFall(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
print("A model with a humanoid touched!")
else
print("Something else touched!")
end
end
Part.Touched:Connect(WhenFall)
This will work, make sure the other part that triggers the event to fire doesn’t belong to a model which also has a Humanoid instance otherwise it’ll behave in the same way as when you were touching the part with your own character.
This seems to work, but if I remove the print(“A model with a humanoid touched!”) then whenever I touch it, I get “Something else touched!” although im the one touching it.
every time i stop touching it and touch it again, i get one “Something else touched!” but if i stay touching the brick i get multiple “You touched” why is this?
For the first point, the reason it “Something else touched!” is because the part named “Handle” inside your hair accessory is touching the blue sphere, fixing that is relatively easy. Regarding the second part, Touched/TouchEnded often fires regularly (even when you wouldn’t expect it to due to the way part collision works in Roblox), you can remedy that by adding a debounce to the callback in order to prevent it from executing too frequently.
local Part = script.Parent
local debounce = false
function WhenFall(part)
if debounce then
return
end
if part.Parent:IsA("Accessory") then
return
end
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
debounce = true
print("A model with a humanoid touched!")
task.wait(5) --cooldown length
debounce = false
else
print("Something else touched!")
end
end
Part.Touched:Connect(WhenFall)