What I'm trying to do is save the player's cash I have never used DataStore before so I have no idea what I'm doing.
Here is my attempt:
local DataStoreService = game:GetService("DataStoreService") game.Players.PlayerAdded:Connect(function(plr) repeat local Cash = DataStoreService:GetDataStore(plr.Name.. "'s cash") local success, CashAmount = pcall(function() return Cash:GetAsync(plr.Name.. "'s cash") end) if success then print("Current Cash:", CashAmount) plr.PlayerScripts.Cash.Value = math.floor(CashAmount / 2) else repeat local success, err = pcall(function() Cash:SetAsync(plr.Name.. "'s cash", plr.PlayerScripts.Cash.Value) end) if success then print("Success!") else print("Failed!") end until success end until success end) game.Players.PlayerRemoving:Connect(function(plr) repeat local Cash = DataStoreService:GetDataStore(plr.Name.. "'s cash") local success, newName = pcall(function() return Cash:UpdateAsync(plr.Name.. "'s cash", plr.PlayerScripts.Cash.Value) end) if success then print("Updated ".. plr.Name .."'s Cash") else print("Failed!") end until success end)
It repeatedly prints out "Failed!" In the output when I playtest it on Roblox Studio I have tried changing the script by adding the repeat loop to make sure it doesn't fail
It is a regular Script and is inside ServerScriptService