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

How to save data using module script?

Right now I have been using data stand consists of making folders in the Player and putting values in that folder. Currently I have 3 values, MaxExp, Exp and Level but I have heard that there are better ways so saving player data that is safer and more convenient that the method I have been using. I heard that using modules are better in saving player data but the problem is, I don't really understand how they do those kind of data saving system. Can someone help me with this or send me links that can help me understand how to make a data saving system using module script? Also, I have read the roblox dev forum about Saving Player Data and I didn't really understand how it worked. P.S. I know how module script works.

1 comment

0

Module script is like a box filled with functions, so if you use functions instead of it won't really matter unless other factors.

1 answer

✓ Accepted answer

Haha... Module scripts can't run code! You're using a module script because the icon looks better, right? You can require the module in a script and run code like that.

Module

local m = {}

function m.New()
	local k = {}
	-- create data stuff
	function k:Get()
		local r = {}
			function r:Save()

			end
		return r
	end
	-- other data functions
	return k
end

return m

Script

local thicc = require(game.ReplicatedStorage.DataStoreModule)
local datastore = thicc.New()
local data = {}

game.Players.PlayerAdded:Connect(function(Player)
	data[Player.UserId] = datastore:Get(Player.UserId)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	data[Player.UserId]:Save()
end)

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