Hey guys, I have made a data store to save cash. Seems to act weird, sometimes saves, sometimes doesn’t here it is:
Script is located in the workspace
local DataStore = game:GetService(“DataStoreService”):GetDataStore(“StoreName”)
game.Players.PlayerAdded:connect(function(player)
local key = “key-”…player.userId
local folder = Instance.new(“Folder”,player)
folder.Name = “leaderstats”
local cash = Instance.new(“IntValue”,folder)
cash.Name = “Cash”
local save = DataStore:GetAsync(key)
if save then
cash.Value = save[1]
else
local cashload = {cash.Value}
DataStore:SetAsync(key,cashload)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local key = “key-”…player.userId
local load = {player.leaderstats:FindFirstChild(“Cash”).Value}
DataStore:SetAsync(key,load)
end)
(Sorry I don’t know how to paste it properly.)