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 from a script in a gui?

i have this script i want to teleport a player when they click a button but i cant seem to figure out how to go about this any help

Here is the script:

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Parent.Parent.PlayerStats.Intro.Value == 0 then
		local player = game.Players.LocalPlayer
		player.Character.Position = Vector3.new (20,20,29)
	else
			wait()
	end
end)

thanks in advance!

(if your wondering why i have a else there with a wait its so that something else happens when they click it and their value isn't 0 anymore, which will happen after the first time they click the button. im going to do that after i finish the first half of the script but i know how to do that and im just wondering how to do the first bit.)

2 answers

✓ Accepted answer

you can't teleport a model (player.Character), so you should move the player's HumanoidRootPart instead

script.Parent.MouseButton1Click:Connect(function()
    if script.Parent.Parent.Parent.Parent.PlayerStats.Intro.Value == 0 then
        local player = game.Players.LocalPlayer
        player.Character.HumanoidRootPart.Position = Vector3.new (20,20,29)
    else
            wait()
    end
end)

1 comment

0

You can move a Character with :MoveTo(Vector3)

Normally that work.

local PlayerService = game:GetService('Players')
local Player = PlayerService.LocalPlayer
local PlayerStats = Player:WaitForChild('PlayerStats')

script.Parent.MouseButton1Click:Connect(function()
    if PlayerStats.Intro.Value == 0 and Player.Character then
        Player.Character:MoveTo(Vector3.new (20,20,29))
    end
end)

Use a LocalScript.

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