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

How to teleport player with clickdetector?

I want to make players get teleported to a certain spot after clicking a button, my code below, don't know what I'm doing wrong.

place = CFrame.new(123.5,3608.89,446)
script.Parent.ClickDetector.MouseClick:Connect(function(p)
	local humanoid = p.Parent:findFirstChild("Humanoid")
	if (humanoid ~= nil) then
		humanoid.Torso.CFrame = place
	end
end)

2 answers

✓ Accepted answer

Since AProgrammR's script didn't work, this might work better:

place = CFrame.new(123.5,3608.89,446)
script.Parent.ClickDetector.MouseClick:Connect(function(p)
local char = p.Character
	if char then
		char.Torso.CFrame = place
	end
end)

The concept is similar, just adapted for R6 rigs, and without the semicolon.

1 comment

0

There was a problem stopping me from clicking it, this worked, and AProgrammR's probably would've too, sorry!

"p" does not return the player's character but rather returns the player object. You can get the character by using p.Character. Try:

place = CFrame.new(123.5,3608.89,446)
script.Parent.ClickDetector.MouseClick:Connect(function(p)
	if p.Character then
		p.Character.HumanoidRootPart.CFrame = place;
	end
end)

Hope it helps!

1 comment

0

Sorry, it doesn't seem to work

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