Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

use vectors in the cframe

0

Didn't work

1 answer

✓ Accepted answer

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

4 comments

0

Laugh is actually a sound

0

o then ignore that stuff then

0

lemme change it

0

Thanks, didn't know I needed to use the root part

This discussion is preserved as it was. New answers, comments, and votes are closed.