Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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 ;)

This discussion is preserved as it was. New answers, comments, and votes are closed.