local Players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService")
local StageStore = DataStore:GetDataStore("Stage")
local Stages = workspace:WaitForChild("CheckpointStages")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Stage = Instance.new("IntValue")
Stage.Parent = leaderstats
Stage.Name = "Stage"
local StageData
local success, errorMessage = pcall(function()
StageData = StageStore:GetAsync(player.UserId)
end)
if success then
if StageData then
local character = player.Character or player.CharacterAdded:Wait()
if player.leaderstats.Stage.Value == 0 then
local character = player.Character or player.CharacterAdded:Wait()
character:PivotTo(Stages:FindFirstChild(tostring(1)).CFrame + Vector3.new(0,5,0))
else
character:PivotTo(Stages:FindFirstChild(tostring(player.leaderstats.Stage.Value)).CFrame + Vector3.new(0,5,0))
end
else
local character = player.Character or player.CharacterAdded:Wait()
character:PivotTo(Stages:FindFirstChild(tostring(1)).CFrame + Vector3.new(0,5,0))
end
print("Success!")
else
warn(errorMessage)
end
end)
Players.PlayerRemoving:Connect(function(player)
local StageData
local success, errorMessage = pcall(function()
StageData = StageStore:SetAsync(player.UserId, player.leaderstats.Stage.Value)
end)
if success then
if StageData then
print("Saved Data for "..player.Name)
else
print("Failed to Save Data for "..player.Name)
end
print("Success!")
else
warn(errorMessage)
end
end)
game:BindToClose(function()
task.wait()
end)
I also have a script outside of this that changes leaderstats.Stage
’s value so that it can actually change every time you go to the next stage.
The problem I’m having is it not saving. All the prints say "Success!"
but nothing gets saved. I don’t really ever work with DataStores so I’m a noob for these types of problems.
Any help is appreciated!