when i went to rename the data Store, I noticed this error that happens when a user doesn’t have any data stored, it said "ServerScriptService.RobloxWorld_DataStore:37: attempt to index nil with ‘CheckPoint’ "
local players = game:GetService(“Players”)
local dataStoreService = game:GetService(“DataStoreService”)
local saveDataStore = dataStoreService:GetDataStore(“CheckPoints7”)local function savePlrData(plr)
local success,err = pcall(function()local saveData = {} for _,stat in pairs(plr.leaderstats:GetChildren()) do saveData[stat.Name] = stat.Value end saveDataStore:SetAsync(plr.UserId,saveData)
end)
if not success then return err end
endplayers.PlayerAdded:connect(function(plr)
local stats = Instance.new(“Folder”)
stats.Name = “leaderstats”
stats.Parent = plrlocal CHECKPOINTS = Instance.new(“IntValue”)
CHECKPOINTS.Name = “CheckPoint”
CHECKPOINTS.Parent = stats
CHECKPOINTS.Value = 1local success, currentData = pcall(function()
return saveDataStore:GetAsync(plr.UserId)
end)if success then
for _,stat in pairs(stats:GetChildren()) do stat.Value = currentData[stat.Name] end
else
print(plr.Name… " Has No Data")end
local function TeleportToCheckpoint(chr, checkpoint)
if checkpoint ~= nil then
local part = workspace.CheckPoints:WaitForChild(checkpoint)
repeat wait() until chr.Humanoid
if chr.PrimaryPart ~= nil then
chr.PrimaryPart.CFrame = part.CFrame + Vector3.new(0,1,0)
endend
end
plr.CharacterAdded:connect(function(char)
if CHECKPOINTS.Value ~= nil then
local part = workspace.CheckPoints:WaitForChild(CHECKPOINTS.Value)
local PRIMPART = char:WaitForChild(“HumanoidRootPart”)
repeat wait() until PRIMPART ~= nil
if PRIMPART ~= nil then
PRIMPART.CFrame = part.CFrame + Vector3.new(0,1,0)
endend
end)
end)
players.PlayerRemoving:connect(function(plr)
local err = savePlrData(plr)
if err then print(err) end
end)game:BindToClose(function()
for _,plr in pairs(players:GetPlayers()) do
local err = savePlrData(plr)
if err then print(err) end
end
wait(2)
end)