hey, so I’ve ran into a problem with Datastores where it wont save when a person leaves, didnt try manual saving yet, but here it is
for some reason it can not locate the “AllStats” folder even though it is there
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local allStatuses = Instance.new("Folder")
allStatuses.Name = "AllStatuses"
allStatuses.Parent = character
local auraStatus = Instance.new("StringValue")
auraStatus.Value = "Off"
auraStatus.Name = "AuraStatus"
auraStatus.Parent = allStatuses
local formStatus = Instance.new("StringValue")
formStatus.Value = "Base"
formStatus.Name = "FormStatus"
formStatus.Parent = allStatuses
local allStats = Instance.new("Folder")
allStats.Name = "AllStats"
allStats.Parent = character
local s1 = Instance.new("IntValue")
s1.Name = "Strength"
s1.Parent = allStats
local s2 = Instance.new("IntValue")
s2.Name = "Defense"
s2.Parent = allStats
local s3 = Instance.new("IntValue")
s3.Name = "Ki"
s3.Parent = allStats
local strdata
local defdata
local success, failure = pcall(function()
strdata = statStore:GetAsync(player.UserId.."-strength")
end)
if success then
s1.Value = strdata
print("Data loaded successfully")
else
print("Failed to load data")
warn(failure)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, failure = pcall(function()
statStore:SetAsync(player.UserId.."-strength",player.Character.AllStats.Strength.Value) --doesnt save here
end)
if success then
print("Data Saved")
else
print("Failed")
warn(failure)
end
end)
game:BindToClose(function(player)
local success, failure = pcall(function()
statStore:SetAsync(player.UserId.."-strength",player.Character.AllStats.Strength.Value)
end)
end)