Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make an NPC make a player teleport when touched?

Asked by 5 years ago

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

0
use vectors in the cframe greatneil80 2647 — 5y
0
Didn't work CaptainAlien132 225 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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()

0
Laugh is actually a sound CaptainAlien132 225 — 5y
0
o then ignore that stuff then User#23365 30 — 5y
0
lemme change it User#23365 30 — 5y
0
Thanks, didn't know I needed to use the root part CaptainAlien132 225 — 5y
Ad

Answer this question