hello,
i made a datestore script but for some reason the script only works half the time. i have used this script in the past and it usssually works but i dont know why its not now.
script:
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local Cash = player.LeaderStatistics.Cash
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId…"-Cash")
end)
if success then
Cash.Value = data
else
print("There was an error whilst getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId…"-Cash",player.LeaderStatistics.Cash.Value)
end)
if success then
print("Player Data Was Successfully saved")
else
print("There was an error when saving")
warn(errormessage)
end
end)```
You might need this cash script that i use:
local function onPlayerJoin(player)
local leaderstats = Instance.new(‘Folder’)
leaderstats.Name = “LeaderStatistics”
leaderstats.Parent = player
local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
This Might Help As Well:
Thank You