I am making a Skip Stage for my Obby and I have a Skip Stage feature. I have a screen GUI --> TextButton --> Local Script.
I have named the checkpoints as for example, the first checkpoint will be called 1, the next checkpoint 2 and so on.
I do have a touch handler script in the Checkpoints folder which runs when a checkpoint is touched. It is as follows:
local Checkpoints = script.Parent
for i,v in pairs(Checkpoints:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player.leaderstats.Checkpoint.Value < tonumber(v.Name) then
player.leaderstats.Checkpoint.Value = tonumber(v.Name)
end
end
end
end)
end
end
The Local Script which is inside the text button (which should teleport me to the next Checkpoint) is causing out an error. It increases my leaderstats.Checkpoint's Value but just doesn't Teleport me.
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats"):FindFirstChild("Checkpoint")
local hasLimits = true
local Limits = 3
script.Parent.MouseButton1Click:connect(function()
if hasLimits == true then
if Limits ~= 0 then
Limits = Limits - 1
script.Parent.Text = "Skip Stage ("..Limits..")"
leaderstats.Value = leaderstats.Value + 1
if player ~= nil then
if player.Character ~= nil then
if player.Character:FindFirstChild("Humanoid").Health > 0 then
player.Character.HumanoidRootPart.CFrame = game.Workspace:FindFirstChild(leaderstats.Value).CFrame + Vector3.new(0,3,0)
end
end
end
end
else
if player ~= nil then
if player.Character ~= nil then
if player.Character:FindFirstChild("Humanoid").Health > 0 then
player.Character.HumanoidRootPart.CFrame = game.Workspace:FindFirstChild(leaderstats.Value).CFrame + Vector3.new(0,3,0)
end
end
end
end
end)
And in the output is says "Players.Soban06.PlayerGui.ScreenGui.TextButton.LocalScript:15: attempt to index nil with 'CFrame'".
Please tell me how to fix this.
Thanks

2 comments
If Checkpoints is a Folder, or stored as some sort od descendant of workspace, you may have forgotten to dive into said folder as you’re looking for workspace.3 (example checkpoint). Also try, tostring(leaderstats.Value)
Thanks. It worked. But there is one problem. If I am on my last level and I press the skip stage button, it still increases the value on my leader board even though I don't have those many stages. How can I stop the leader board values from increasing if I am on the last level?