So i have a datastore script,and there are three stats : cash,level and exp.So when i press play and earnt a few levels,some cash and exp and stop and play again,the exp resets to 0 and the cash and level resets to the same value.How does this keep happening?Also i realised that whenever it resets,the cash value and the level value is the same However,it works fine on other games i used this script in and there were no resets script:
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("cashSaveSystem")
local ds2 = datastore:GetDataStore("killsavesystem")
local ds3 = datastore:GetDataStore("levelupsave")
game.Players.PlayerAdded:connect(function(plr)
local stats = Instance.new ("IntValue", plr)
stats.Name = "leaderstats"
local Experience = Instance.new ("IntValue",stats)
Experience.Name = "EXP"
local level = Instance.new ("IntValue",stats)
level.Name = "Level"
local cash = Instance.new("IntValue",stats)
cash.Name = "Cash"
Experience.Value = ds1:GetAsync(plr.UserId) or 0
ds1:SetAsync(plr.UserId, Experience.Value)
cash.Value = ds2:GetAsync(plr.UserId) or 0
ds2:SetAsync(plr.UserId, cash.Value)
level.Value = ds3:GetAsync(plr.UserId) or 0
ds2:SetAsync(plr.UserId,level.Value)
Experience.Changed:Connect(function()
ds1:SetAsync(plr.UserId, Experience.Value)
end)
cash.Changed:Connect(function()
ds2:SetAsync(plr.UserId, cash.Value)
end)
level.Changed:Connect(function()
ds3:SetAsync(plr.UserId,level.Value)
end)
Experience.Changed:connect(function()
level.Value = math.floor(Experience.Value / 1000)
end)
end)
Level up script
local player = game.Players.LocalPlayer
local Leaderstats = player:WaitForChild('leaderstats')
local level = Leaderstats:WaitForChild ('Level')
local xp = Leaderstats:WaitForChild('EXP')
level.changed:connect(function()
if xp.Value < 1000 then
level.Value = 0
elseif
xp.Value >= 1000
then level.Value = 1
xp.Value = 0
end
end)

1 comment
it does have api and i tried playing ingame