Hi, I want to create a script that when a player presses a button, they get teleported to a certain position.
I would like some help or information about how to create this script. Thanks!
If you are using a ClickDetector you can either use :MoveTo() or :SetPrimaryPartCFrame() on their character.
you gotta make a local script first use MouseButton1Click function to check if gui is clicked then make a variable called plr which contains the local player then find the character of the local player then change the CFrame of the humanoidrootpart to wherever you want
Thanks, but I’m not using a Gui.
If I do :MoveTo(10, 10, 10), will it teleport the player to that position?
It will do that. You can use either but I personally prefer SetPrimaryPartCFrame().
moveto function will make the player walk to that position
Isn’t SetPrimaryPartCFrame() about CFrames?
Oh I’m stupid. Yeah it is CFrames. Are you getting a part’s position or putting co-ordinates?
So, I’m trying to teleport the player to a position that I choose when the player clicks the ClickDetector Part
:MoveTo() will teleport the player without changing the orientation.
:SetPrimaryPartCFrame() will teleport at the part’s CFrame.
Ok, Can you tell me how I can put :MoveTo()? Do I put it after the function?
Sorry, I’m not good at scripting.
Gui
script.Parent.MouseButton1Click:Connect(function()
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Root = Character:FindFirstChild("HumanoidRootPart")
local Part = game.Workspace.Teleports.Position1
if Root ~= nil then
Root.CFrame = CFrame.new(Part.Position)
end
end)
ClickDetector
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
local Character = Player.Character
local Root = Character:FindFirstChild("HumanoidRootPart")
local Part = game.Workspace.Teleports.Position1
if Root ~= nil then
Root.CFrame = CFrame.new(Part.Position)
end
end)
Screenshot
Script 1:
local part = game.Workspace.ExamplePart
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
plr.Character:MoveTo(part.Position)
end)
Script 2:
local part = game.Workspace.ExamplePart
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
plr.Character:SetPrimaryPartCFrame(part.CFrame)
end)
Thank you for your information, but I’m not using a Gui for this.
I will test this script out and tell you.
There is gui and click detector.
Just tell us what are you using to make the teleport
Oh, sorry, I didn’t see that you wrote a ClickDetector script. I’m using a ClickDetector.
Ok, I will check it out, thanks!