Hello, I am trying to make a trap with some animations that are triggered by a touched event.
As I was making my trap I noticed that sometimes the Touched Event would not work. The Output would just give me “HumanoidRootPart is not a valid member of Accessory…”
![]()
I have already tried fixing this by checking if the character model found is even a model. That did not work.
Here is the code used:
local TweenService = game:GetService("TweenService")
local Robux = script.Parent.Robux
Busy = false
--[[ Main Function ]]--
function start(hit)
if not Busy then
Busy = true
local Char = hit.Parent
if not Char:IsA("Model") then
Char = hit.Parent.Parent
end
if not Char:IsA("Model") then
Char = hit.Parent.Parent.Parent
end
if not Char:IsA("Model") then
Char = hit.Parent.Parent.Parent.Parent
end
hit.Parent.HumanoidRootPart.CFrame = script.Parent.TPDestination.CFrame
Char.Humanoid.WalkSpeed = 0
Char.Humanoid.JumpPower = 0
wait(5)
TweenService:Create(script.Parent.Trap1Door1.Hinge1, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = script.Parent.Trap1Door1.Hinge1Finish.CFrame}):Play()
script.Parent.Trap1Door1.DoorOpen:Play()
wait(3)
TweenService:Create(script.Parent.Trap1Door1.Hinge1, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {CFrame = script.Parent.Trap1Door1.Hinge1Start.CFrame}):Play()
wait(1)
script.Parent.Trap1Door1.DoorClose:Play()
script.Parent.Pipe.SoundPart.Vacuum_Start:Play()
wait(1.044)
script.Parent.Pipe.SoundPart.Vacuum_Running:Play()
while Char.Humanoid.Health > 0 do
wait(0.6)
local RobuxClone = Robux.Robux:Clone()
RobuxClone.Parent = script.Parent.RobuxStorage
TweenService:Create(RobuxClone, TweenInfo.new(3, Enum.EasingStyle.Linear), {CFrame = Robux.Robux1Finish.CFrame}):Play()
Char.Humanoid:TakeDamage(5)
end
end
end
--[[ TP Walls ]]--
script.Parent.TPWall1.Touched:Connect(function(hit)
start(hit)
end)
script.Parent.TPWall2:Connect(function(hit)
start(hit)
end)
script.Parent.TPWall3:Connect(function(hit)
start(hit)
end)
script.Parent.TPWall4:Connect(function(hit)
start(hit)
end)
script.Parent.TPWall5:Connect(function(hit)
start(hit)
end)
I hope you can help me because I have had this problem for a long time now. (in other projects)