hitbox.Touched:Connect(function(touchPart)
print("Touched part: ", touchPart.Name)
if character:IsAncestorOf(touchPart) then return end
local hitSound = tool.Handle:FindFirstChild("Hit")
hitSound:Play()
print("Sound played upon touching: ", touchPart.Name)
end)
I’m trying to get this Handle to play a sound when its touched, but it only plays when it hits the character, and not the rest of the workspace.
Why doesn’t this work? Does BasePart.Touched have a cooldown?
This means if the part touching isn’t a descendant of the character your code will do nothing. Basically, If It isn’t inside the character then don’t consider it
This still only prints the character as being touched, and nothing else (even though it has touched the Baseplate.
local hitbox = tool.Handle.Hitbox
hitbox.Touched:Connect(function(touchPart)
print("Touched part: ", touchPart.Name)
if not character:IsAncestorOf(touchPart) then
local hitSound = tool.Handle:FindFirstChild("Hit")
hitSound:Play()
print("Sound played upon touching: ", touchPart.Name)
end
end)
If by “firing once” you mean “only firing with certain BaseParts”, which in your case appears to be characters, then you’re most likely trying to have a BasePart that is Anchored to trigger its event. Refer to the documentation:
This event only fires as a result of physical movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be Anchored at the time of the collision.