This is the error I got: ServerScriptService.CheckPointScript:23: attempt to index nil with 'leaderstats' - Server - CheckPointScript:23
This is the script below. Please and Thank you.
local Players = game:GetService("Players")
local CheckpointsFolder = game.Workspace.CheckPoint
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Stage = Instance.new("IntValue")
Stage.Name = "Stage"
Stage.Parent = leaderstats
end)
for _, v in pairs(CheckpointsFolder:GetChildren()) do
if v:isA("BasePart") then
v.Touched:Connect(function(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
local stageValue = player.leaderstats.Stage
if player and stageValue.Value < tonumber(v.Name) then
stageValue.Value = v.Name
end
end)
end
end