Issues with Autosave script for an Obby
I got the Autosave + Stage script through a tutorial from 2 different Youtubers I feel like there are a few properties i should change to make it work?
---Stage Script----
local STAT_NAME = "Stage"
local PREVENT_SKIPPING = true
local checkpoints = {}
local i = 1
while true do
local checkpoint = Workspace:FindFirstChild("Checkpoint " .. i, true)
if not checkpoint then print("Last Checkpoint : " .. i-1) break end
table.insert(checkpoints, checkpoint)
i = i + 1
end
game.Players.PlayerAdded:connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Model", player)
leaderstats.Name = "leaderstats"
local checkpointStat = Instance.new("IntValue", leaderstats)
checkpointStat.Name = STAT_NAME
checkpointStat.Value = 1
player.CharacterAdded:connect(function(character)
local goto = checkpoints[checkpointStat.Value]
if goto then
repeat wait() until character.Parent
character:MoveTo(goto.Position)
else
warn("Checkpoint " .. checkpointStat.Value .. " not found")
end
end)
end)
for index, checkpoint in ipairs(checkpoints) do
checkpoint.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if not humanoid or humanoid.Health <= 0 then return end
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return end
local checkpointStat = leaderstats:FindFirstChild(STAT_NAME)
if not leaderstats then return end
if (PREVENT_SKIPPING and checkpointStat.Value + 1 == index) or (not PREVENT_SKIPPING and checkpointStat.Value < index) then
checkpointStat.Value = index
end
end)
end```
-----AutoSave Script------
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData")
local function SavePlayerData(player)
local success,errormsg = pcall(function()
local SaveData = {}
for i,stats in pairs(player.leaderstats:GetChildren()) do
SaveData[stats.Name] = stats.Value
end
SaveDataStore:SetAsync(player.UserId,SaveData)
end)
if not success then
return errormsg
end
end
Players.PlayerAdded:Connect(function(player)
local Stats = Instance.new("Folder")
Stats.Name = "leaderstats"
Stats.Parent = player
local Stage = Instance.new("StringValue")
Stage.Name = "Stage"
Stage.Parent = Stats
Stage.Value = 1
local Data = SaveDataStore:GetAsync(player.UserId)
if Data then
print(Data.Stage)
for i,stats in pairs(Stats:GetChildren()) do
stats.Value = Data[stats.Name]
end
else
print(player.Name .. " has no data.")
end
player.CharacterAdded:Connect(function(character)
local Humanoid = character:WaitForChild("Humanoid")
local Torso = character:WaitForChild("HumanoidRootPart")
wait()
if Torso and Humanoid then
if Stage.Value ~= 0 then
local StagePart = workspace.Stages:FindFirstChild(Stage.Value)
Torso.CFrame = StagePart.CFrame + Vector3.new(0,1,0)
end
end
end)
end)
Players.PlayerRemoving:Connect(function(player)
local errormsg = SavePlayerData(player)
if errormsg then
warn(errormsg)
end
end)
game:BindToClose(function()
for i,player in pairs(Players:GetPlayers()) do
local errormsg = SavePlayerData(player)
if errormsg then
warn(errormsg)
end
end
wait(2)
end)
This is the error I’m getting in the output:
19:30:43.913 - 502: API Services rejected request with error. HTTP 403 (Forbidden)
19:30:43.915 - Stack Begin
19:30:43.916 - Script ‘ServerScriptService.Save’, Line 36
19:30:43.916 - Stack End
this is the line 36: local Data = SaveDataStore:GetAsync(player.UserId)