I'm trying to make an NPC that'll teleport the player when the upper torso is played, and I want the player to take 50 damage but I can't figure out how to make it work.
script.Parent.Touched:connect(function(p) local humanoid = p.Parent:findFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.LowerTorso.CFrame = CFrame.new(51.56, 3.2, 184.24) humanoid.Health = humanoid.Health - 50 wait(.2) script.Parent.Parent.Head.Laugh:Play() end end)
Thanks if you can help
your accessing the humanoid variable to get the players torso which wouldn't work since LowerTorso isnt a child of it as you defined the variable as the Humanoid
. also you don't need to check if the player's humanoid
isnt nil.
script.Parent.Touched:Connect(function(p) local humanoid = p.Parent:FindFirstChild("Humanoid") if humanoid then p.Parent.HumanoidRootPart.CFrame = CFrame.new(51.56, 3.2, 184.24) humanoid.Health = humanoid.Health - 50 wait(.2) script.Parent.Parent.Head.Laugh:Play() end end) -- indent your code
NOTE use the player's HumanoidRootPart
so it wont error for R6 and also :connect()
and :findFirstChild()
is deprecated, use :Connect()
and :FindFirstChild()