My DataStore Permissions are enabled, i tried everything, but it doesn’t work, the script is in the ServerScriptService. The Script is also enabled. Heres the code
local dataStoreService = game:GetService("DataStoreService")
local store = dataStoreService:GetDataStore("Test1")
function saveData(plr)
local success, error = pcall(function()
store:SetAsync(plr.UserId.."-cash", plr.leaderstats.Cash.Value)
store:SetAsync(plr.UserId.."-days", plr.leaderstats.Days.Value)
print("Saved Data")
end)
end
game.Players.PlayerAdded:Connect(function(plr)
local cashData
local daysData
local success, error = pcall(function()
cashData = store:GetAsync(plr.UserId.."-cash")
daysData = store:GetAsync(plr.UserId.."-days")
end)
if error then warn(error) end
if cashData then
print(cashData)
plr.leaderstats:WaitForChild("Cash").Value = cashData
end
if daysData then
print(daysData)
plr.leaderstats:WaitForChild("Days").Value = daysData
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
saveData(plr)
end)
game:BindToClose(function()
for i,plr in ipairs(game.Players:GetPlayers()) do
saveData(plr)
task.wait()
end
end)
Also the script is also a parent of a script that adds leaderstats, somebody help me pls
If it is ran in studio & the game hasn’t released - that will definitely cause a bug, if so first make the game public and test in roblox and not roblox studio.
You have to use RemoteEvents PlayerRemoving Dosen’t Work game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function() --"Save stuff you already wrote" end)