Moving player to part

So i am making an obby with gui navigation to move between stages, and I encountered a problem.
I don’t really know how to move the player to the specific part that they are going to.
current code and plan:

local Player = game:GetService("Players").LocalPlayer
local rightbutton = Player.PlayerGui.LevelGui.Main.Right
local levelchange = Player.PlayerGui.LevelGui.Main.level
local lastStage = Player.leaderstats.Stage
local checkpointWord = "Checkpoint"

rightbutton.MouseButton1Click:Connect(function() 
	if (levelchange == lastStage) then
		return "error, last stage currently unlocked"
	else
		local nextPoint = levelchange + 1
		local placeToMove = checkpointWord .. nextPoint
		local partToMove = game.Workspace.placeToMove
		Player.CFrame = partToMove.CFrame --is this how i do it?
	end
end)

my checkpoints are called "Checkpoint"x, where x is the number. Example: “Checkpoint2”
i’m still new to scripting, so the answer may be obvious, but I don’t know what to do.

4 Likes
Player.character:WaitForChild("Humanoid"):MoveTo(PartToMove.Position) -- or CFrame

It’s probably not gonna work but you can try (i just know that it works for npcs but i don’t know if this method works for player)

2 Likes

do i put this in local script or regular?

2 Likes

use player.Character.HumanoidRootPart.CFrame

1 Like

the script only works on server side because if you do on local script the position wont change on server

1 Like

as in instead of Player.character:WaitForChild(“Humanoid”)?

1 Like

and you could run that on the client and it would still work

1 Like

Player.Character.HumanoidRootPart.CFrame

1 Like

the humanoidrootpart is the primary part of the character so when you set its cframe the whole character will move

1 Like

my last question is, if i use variables like a string to make the name, and just do

game.Workspace.partToMove -- the variable constructed by strings and numbers 

will it work as a valid id if a part with that name exists?

do you mean like uhm

local end_pos = part.CFrame
local character = player.Character

i meant like
(pretend i have parts called Hello1, Hello2, etc.)

local firstpart = "Hello"
local secondpart = 2
local fullpart = firstpart .. secondpart
local partInWorld = game.Workspcae.fullpart

you’d have to do workspace:FindFirstChild(fullpart)

1 Like

i just tested the script, it seems to not want to teleport me?

local Player = game:GetService("Players").LocalPlayer
local rightbutton = Player.PlayerGui.LevelGui.Main.Right
local levelchange = Player.PlayerGui.LevelGui.Main.level
local lastStage = Player.leaderstats.Stage
local checkpointWord = "Checkpoint"

rightbutton.MouseButton1Click:Connect(function() 
	if (levelchange == lastStage) then
		print("error")
		return "error, last stage currently unlocked"
		
	else
		print("hello?") -- doesnt print this
		local nextPoint = levelchange + 1
		local placeToMove = checkpointWord .. nextPoint
		local partToMove = workspace:FindFirstChild(placeToMove)
		Player.Character.HumanoidRootPart.CFrame = partToMove.Cframe
	end
end)

should the .LocalPlayer be removed?

is this definitely a local script?

yes
yep
yea
roblox minimum is annoying

if this isnt being printed then

this condition is being met

but are the levels values? aaaaaaaa

but it is also not printing error, so is it just not running?

are these values?

:weary::weary::weary::weary::weary::weary::weary::weary: