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

How to create a teleport when clicked a button?

Asked by
Guga390 -3
6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
Thank you so much! Guga390 -3 — 6y
0
No problem man! if it helped would you mind accepting the answer? PoePoeCannon 519 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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.

Answer this question