I made this data store script to save the cash value every 20 seconds. However, according to the console, the value attempted to be saved will always result in the value I saved in studio. I want to make my game FE, however this script refuses to work with FE! Please help... It would be greatly appreciated! (Also I wrote print("imBroken!!!") out of pure frustration, if you where wondering why it was there.)
local Storage = game:GetService('DataStoreService'):GetDataStore("SaveCash")
game.Players.PlayerAdded:connect(function(plr2)
print("imBroken!!")
local Cash = plr2:WaitForChild("Backpack").PlayerCash
Cash.Value = 0
local SavedCash = Storage:GetAsync(plr2.userId .. "-Cash")
if SavedCash ~= nil then
print(SavedCash)
Cash.Value = SavedCash
end
while true do
wait(20)
print("SAVE")
local id = plr2.userId
local CashValue = plr2.Backpack.PlayerCash.Value
game:GetService('DataStoreService'):GetDataStore("SaveCash"):SetAsync(id.."-Cash", CashValue)
print(Storage:GetAsync(plr2.userId .. "-Cash"))
end
end)
