Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

DataSaveAsync Script is only working In Solo Mode on Roblox Studio?

Asked by 5 years ago
wait(3)
print("Script is now running, Saving Data...")
local DSService = game:GetService("DataStoreService"):GetDataStore("EmoteSimCashData")
game.Players.PlayerAdded:Connect(function(plr)
    local playerId = "id-"..plr.UserId
    local DataToSave = plr.PlayerGui.Amount.Frame.Balance

    local GetSaved = DSService:GetAsync(playerId)
    if GetSaved then
        DataToSave.Value = GetSaved[1]
    else
        local NumbersForSaving = {DataToSave.Value}
        DSService:SetAsync(playerId,NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local playerId = "id-"..plr.UserId
    local Savetable = {plr.DataToSave.Value}
    DSService:SetAsync(playerId,Savetable)


end)

I want to know why this script is only running in Solo Studio, and not In-game. Any Idea why?

Thanks in advance.

1 answer

Log in to vote
0
Answered by 5 years ago

It might be because of the game was closing and didn't have time to run the PlayerRemoving event. For this reason, Roblox have game:BindToClose(). You might wanna read that ;)

Ad

Answer this question