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

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

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)

2 comments

0

What about it doesn't work? Also, post all your attempts

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.

2 answers

✓ Accepted answer

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

2 comments

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

0

If this helped, please make sure to check-mark this as answered :) Good luck coding!

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())

1 comment

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.

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