Hello. I got this error while making a checkpoint script:
Script:
local currentstages = game.Workspace.currentstages
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 1
stage.Parent = leaderstats
end
Players.PlayerAdded:Connect(leaderboardSetup)
for _, stages in pairs(game.Workspace.currentstages:GetChildren()) do
stages:FindFirstChild("CheckPoint", true).Touched:Connect(function()
local player = game.Players:GetPlayerFromCharacter(stages.SpawnPoint.Parent)
if player then
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats:WaitForChild("Stage")
if stages.Name == stage.Value - 1 then
stage.Value = stage.Value + 1
end
end
end)
end