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

How do I teleport a player to a position after they have clicked a gui textbutton? It is for a "job"

Asked by 4 years ago

I have tried different ways. This is the most recent:

local player = game.Players.LocalPlayer 
local endingPos = Vector3.new(-17.93, .5, 360.89)

script.Parent.MouseButton1Click:Connect(function(teleport)


local inJobspot = false

function teleport(par1)
    if not inJobspot then

        par1.Character:MoveTo(endingPos)
        inJobspot = true 
end
    end
    end)
0
What about it doesn't work? Also, post all your attempts hiimgoodpack 2009 — 4y
0
Two things: You should indent better, that should help with readability. Also, you should define another function outside of the function, preferably with another name. User#30567 0 — 4y

2 answers

Log in to vote
0
Answered by
Gingerely 245 Moderation Voter
4 years ago

This is actually a pretty simple answer. I'm not sure if yours works, because I did not check but this one works, and I'm sure it will for you too. But make sure that this code is in a LOCAL SCRIPT.

local plr = game.Players.LocalPlayer --// Gets the local player.
local char = plr.Character or workspace.ChildAdded:Wait() --// Gets the player's character.
local endingpos = Vector3.new(0,15,0) --// The position you want.

function teleport() --// Making a function.
    char:MoveTo(endingpos) --// Moving the player to the ending position
end

script.Parent.MouseButton1Click:Connect(teleport) --// Calling the teleport function by clicking script.Parent
0
Like you did in your script you added 'teleport' to your clicking function, that teleport would be the player and what you did was you made the player a function Gingerely 245 — 4y
0
If this helped, please make sure to check-mark this as answered :) Good luck coding! Gingerely 245 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try the following. I haven't yet tried it.

local player = game.Workspace.Player -- This is a current player, so I assume this should be put into a localscript
local endPos = Vector3.new(-17.93, .5, 360.89) -- The end location

function teleport() -- Define function
    player.HumanoidRootPart.CFrame = endPos
end

script.Parent.MouseButton1Click:Connect(teleport())
0
I wouldn't call "teleport" like a function on line 8 if you're just connecting it to an event. It should through an error. CeramicTile 847 — 4y

Answer this question