I am trying to save the stage of a player in an obby game, and teleporting the player to the stage they left off at.
However, it’s not working and keeps saving nil. I believe the problem lies with the SaveAync() part as it’s not printing whether it failed or succeeded.
I tried looking up datastores on the developer page just to confirm that I wasn’t doing anything wrong, but I couldn’t find anything I might have been doing wrong. Furthermore, I also contacted a few friends of mine who are programmers as well so that they can
Here’s the script:
local DataStoreService = game:GetService(“DataStoreService”)
local StageDataStore = DataStoreService:GetDataStore(“StageDataStore”)
local Players = game:GetService(“Players”)
local PlayerHasPlayedBefore = false
Players.PlayerRemoving:Connect(function(Player)
print("Player is leaving!")
local Success, Fail = pcall(function()
StageDataStore:SetAsync("Player - "..Player.UserId, Player.leaderstats.Stage.Value)
end)
if Success then
print("Data saved successfully!")
else
print("Failed!")
end
print(Player.leaderstats.Stage.Value)
end)
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Stage
local Success, Fail = pcall(function()
Stage = StageDataStore:GetAsync("Player - "..Player.UserId, Player.leaderstats.Stage.Value)
print(Stage)
end)
if Success and Stage ~= nil then
print("Data loaded successfully!")
Player.leaderstats.Stage.Value = Stage
print(Stage)
for i,v in pairs(game.Workspace.Checkpoints:GetChildren()) do
if v.Value.Value == Stage then
Character:WaitForChild("HumanoidRootPart").CFrame = v.CFrame
end
end
end
end)
end)