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

What parts of data saving should I worry about when designing my game?

I tend to worry about compatibility too much and how I would save data is something that is getting in the way of me designing a game. Are there game designs which make saving data easier or more difficult? Does it even matter scripting wise? What should I take into consideration when designing my saving system when I know I want to add more content later?

1 answer

You should use 3 functions which I recommend

PlayerAdded, PlayerRemoving and BindToClose

PlayerAdded is for loading the datastore value

PlayerRemoving will fire when a player leave the game

BindToClose will fire when a server shutdowns, server closed, or everyone left the game (you gotta use ipairs loop on this one, since server shutdown is a thing that fire no matter what)

Sometimes PlayerRemoving does not fire fully done (a very small percent but it's still damagable) after player leave the game, i'd recommend you do a loop where it saves the data for everyone every 30 seconds (u wont overlimit)

Heres a concept

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	-- TODO: Load the player data and bla bla bla
end)

Players.PlayerRemoving:Connect(function(player)
	-- TODO: Save the player data
end)

game:BindToClose(function() -- BindToClose is a function, so no :Connect() is needed because it is not a RBXSignal (i forgot the name)
	for i, player in ipairs(Players:GetPlayers()) do
		-- TODO save player data, there is no parameter but it's in the ipairs value thing
	end
end

You can make another script on ServerScriptService so it doesnt interrupt other thing

game:GetService("Players").PlayerAdded:Connect(function(player) -- the purpose of this is to get the player parameter
	while true do -- I would not recommend you to do wait(30) seconds because it fires without waiting 30 seconds, when it end it wait for 30 seconds, its ok if u do it, but why u save the data after loading the data?????
		wait(30)
		-- TODO: use the same KEY and store it with getasync (OF COURSE BRUH)
	end
end

1 comment

0

sorry BAD BAD BAD BAD grammar im not tryhard to be comedy im in a rush

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