hello, I would like to create a script that fires a .Touched event with specific limbs and doesn’t fire with anything else.
Heres my script:
local Part = workspace.Part
local function onPartTouched(Part)
if Part.Name == Character.HumanoidRootPart then
print("Doof")
end
end
Part.Touched:Connect(onPartTouched)
Also, Part.Name is a product of what limb is touched.
Heads up, the BasePart.Touched
event returns the specific part that triggered the event.
You haven’t defined Character, and you’re trying to compare an instance to a string. Two different issues.
There are two ways you can tackle this problem. The first way being the traditional and most common;
local Part = workspace.Part
local function onPartTouched(Part)
if Part.Parent:FindFirstChild("HumanoidRootPart") then
--checks if there is a humanoidrootpart within the part's-parent's model (character.)
print("Doof")
end
end
Part.Touched:Connect(onPartTouched)
The second way to solve this issue would be to revise your current method;
local Part = workspace.Part
local function onPartTouched(Part)
if Part.Name == "HumanoidRootPart" then
--checks if a humanoidrootpart hit the part
print("Doof")
end
end
Part.Touched:Connect(onPartTouched)
1 Like
Why thank you kind stranger, with your resources I have fixed my issue that has overcome me while creating my game. You may take my solution badge as a token of my gratitude.
1 Like