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

How to save data using module script?

Asked by 4 years ago
Edited 4 years ago

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.

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. LinavolicaDev 570 — 4y

1 answer

Log in to vote
1
Answered by
iuclds 720 Moderation Voter
4 years ago

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

Answer this question