Not teleporting to stage when button is pressed

I tried making a button that teleports you to your current stage (just in-case you were at a pervious stage, etc), however it isn’t teleporting the player to the stage, though it gives me an error as stated below. Anyone know why? Thanks!

Script:

script.Parent.MouseButton1Click:Connect(function(player)
	local Character = player.Character
	local cpFolder = game.Workspace:WaitForChild("Checkpoints")
	local respawn2 = cpFolder:WaitForChild(player.hidden.SpawnPoint.Value)
	Character:WaitForChild("HumanoidRootPart").CFrame = respawn2.CFrame + Vector3.new(0,3,0)
end)

Output:
19:48:55.070 Players.Megaificent.PlayerGui.ScreenGui.Lobby.LocalScript:2: attempt to index nil with ‘Character’ - Client - LocalScript:2

Your “player” argument is not referring to the player. Put a like variable: local player = game.Players.LocalPlayer and remove your player argument.

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local Character = player.Character
	local cpFolder = game.Workspace:WaitForChild("Checkpoints")
	local respawn2 = cpFolder:WaitForChild(player.hidden.SpawnPoint.Value)
	Character:WaitForChild("HumanoidRootPart").CFrame = respawn2.CFrame + Vector3.new(0,3,0)
end)

We need more of the code. We can’t see variables like “player”.

Should be:

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function(mouse)
	local Character = player.Character
	local cpFolder = game.Workspace:WaitForChild("Checkpoints")
	local respawn2 = cpFolder:WaitForChild(player.hidden.SpawnPoint.Value)
	Character:WaitForChild("HumanoidRootPart").CFrame = respawn2.CFrame + Vector3.new(0,3,0)
end)
2 Likes

hey can you please send me an asset of the gui you are using?