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

How to teleport the player when he/she interacts with a gui?

I want to make the player teleport to a specific point when he/she interacts with a gui. The code is below, only one line i am having problem with, the rest are fine and works as intended.

local TweenService = game:GetService("TweenService")

local function TweenFromPlace(C1,C2)
	workspace.Camera.CFrame = C1.CFrame
	local TweenProps = {CFrame = C2.CFrame}
	local TI = TweenInfo.new(7.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 1, false, 0)
	TweenPlay = TweenService:Create(workspace.Camera, TI, TweenProps)
	TweenPlay:Play()
end

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.This.Visible = false
	workspace.Camera.CFrame = workspace.Cam1.CFrame
	workspace.Camera.CameraType = Enum.CameraType.Scriptable
	workspace.Camera.CFrame = workspace.Cam1.CFrame
	
	-- this is where i am having problems, the line below
	game.Workspace.AriyanHacker29.HumanoidRootPart.Position = workspace.Part.Position
	
	
	TweenFromPlace(workspace.Cam1, workspace.Cam2)
	wait(7.5)
	TweenFromPlace(workspace.Cam2, workspace.Cam3)
	wait(7.5)
	TweenPlay:Cancel()
	workspace.Camera.CameraType = Enum.CameraType.Custom

	script.Parent.Parent.Visible = true
	script.Parent.Parent.Parent.This.Visible = false
	wait (18)
	print("DONE")
end)

1 answer

local TweenService = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer
--since i assume this is a localscript, we can grab the local player

local function TweenFromPlace(C1,C2)
    workspace.Camera.CFrame = C1.CFrame
    local TweenProps = {CFrame = C2.CFrame}
    local TI = TweenInfo.new(7.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 1, false, 0)
    TweenPlay = TweenService:Create(workspace.Camera, TI, TweenProps)
    TweenPlay:Play()
end

script.Parent.MouseButton1Down:Connect(function()
    script.Parent.Parent.Visible = false
    script.Parent.Parent.Parent.This.Visible = false
    workspace.Camera.CFrame = workspace.Cam1.CFrame
    workspace.Camera.CameraType = Enum.CameraType.Scriptable
    workspace.Camera.CFrame = workspace.Cam1.CFrame
    workspace:WaitForChild(player.Name).HumanoidRootPart.CFrame = CFrame.new(workspace.Part)
	--Vector3 works as well.
    TweenFromPlace(workspace.Cam1, workspace.Cam2)
    wait(7.5)
    TweenFromPlace(workspace.Cam2, workspace.Cam3)
    wait(7.5)
    TweenPlay:Cancel()
    workspace.Camera.CameraType = Enum.CameraType.Custom

    script.Parent.Parent.Visible = true
    script.Parent.Parent.Parent.This.Visible = false
    wait (18)
    print("DONE")
end)

Just some minor changes, hopefully that solves your issue. If not, I'm sorry.

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