Moving player to part

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

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

despite all of these prints, none of them seem to work even if I put it in player scripts

What is game.Workspace.StageChange?

I wrote a giant list explaining everything that you made wrong but I accidently deleted it. (Solution✅ would be appreciated)

(if it doesn’t work explain to me what are you trying to do and record a video showing the Explorer and I’ll remake it)

Here is what you supposed to do to make it work

  1. make a script (Not local script) and put it in ServerScriptService

  2. Paste this code inside

game.Players.PlayerAdded:Connect(function(plr)
	Player = plr
end)

local levelchange = game.Workspace:WaitForChild("StageChange")
local lastStage = Player.leaderstats:WaitForChild("Stage")
local rightbutton = Player.PlayerGui.LevelGui.Main.Right

rightbutton.MouseButton1Click:Connect(function() 
	if (levelchange.Value == lastStage.Value) then
		return "error, last stage currently unlocked"

	else

		local nextPoint = levelchange.Value + 1
		local placeToMove = "Checkpoint" .. nextPoint
		local partToMove = workspace:FindFirstChild(placeToMove)
		Player.Character.HumanoidRootPart.CFrame = partToMove.CFrame

	end
end)

my plan is to make the character move to the part refereced as partToMove when a button is clicked, i want to know the difference between doing workspace.StageChange and workspace:WaitForChild(“StageChange”).

workspace:WaitForChild(“StageChange”) waits unti stagechange is loaded

1 Like

wait so the script you gave me is all i need for this, right?

im getting the same issue as before… ARGH…
its not even running. :frowning:

Can you record a video showing your explorer and explaing exactly what are you trying to do and i will make a new script for you

Do you know how to use remote events? So that you can communicate between the client and the server?

not really, im still new to this

Can you plz give me access to your game and I help you?

here is a quick video i made
This is the video of the game

If you look in the console, it gives you an error saying that StageChange is not found in the workspace

it is there? i dont know why it does that. maybe because it is an intvalue?

sorry, i see you are already using it, do you get a warning that the wait time could be infinite?

i am already doing that… it comes from another script

Oh, Player is nil for some reason. look on line 7, it gives an error (its because you never actually declare a Player variable, ill rewrite the script to let you do that)

ah ok that makes a lot of sense

--LOCAL SCRIPT INSIDE STARTERPLAYERSCRIPTS

local Player = game.Players.LocalPlayer
local levelchange = game.Workspace:WaitForChild("StageChange")
local lastStage = Player.leaderstats:WaitForChild("Stage")
local rightbutton = Player.PlayerGui.LevelGui.Main.Right

rightbutton.MouseButton1Click:Connect(function() 
	game.ReplicatedStorage.ChangeStageEvent:FireServer(lastStage, levelchange)
end)
--SERVER SCRIPT INSIDE SERVERSCRIPTSERVICE

game.ReplicatedStorage.ChangeStageEvent.OnServerEvent:Connect(function(player, lastStage, levelChange)
	local nextPoint = levelChange + 1
	local placeToMove = "Checkpoint" .. nextPoint
	local partToMove = workspace:FindFirstChild(placeToMove)
	player.Character.HumanoidRootPart.CFrame = partToMove.CFrame
end)

this might be wrong or not work, because i cannot test this inside a copy of the place. im basing this off knowledge of your workspace and the script

it says levelgui is not a valid member of playergui,
also it says “player” is an unknown global