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

How to create a teleport when clicked a button?

So, I want to make an elevator in Roblox Studio, but I don't know how. I have buttons, and I want to make a click detector, so if someone clicks it the person gets teleported to a part. How can I do that?

2 answers

✓ Accepted answer

You would put the click detector inside of the model you want the player to click and then you can also put a script inside that model and do...

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local char = player.Character -- get character from player
	char.HumanoidRootPart.CFrame = CFrame.new(x,y,z) -- enter your own coordinates

end)

2 comments

0

Thank you so much!

0

No problem man! if it helped would you mind accepting the answer?

You would insert a click detector into the button first. Since the goal is to teleport the character, you'll also have to change a body part's CFrame. Here's the code I would use:

detector = script.Parent:WaitForChild("ClickDetector") 

detector.MouseClick:Connect(function(player)
	player.Character.Torso.CFrame = CFrame.new(x,y,z) --change this to what you want
end)

Make sure to mark me as the answer if this helps, which I hope it does.

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