How to Update Information in an existing Module Script?

I want to be able to update information within a Module Script from a Script, but I don’t quite know how to go about that. Does anyone have any resources that could help me do this? . . Or any ideas that I could try?

There used to be this one post about Saving Player Data on the Roblox Developer Wiki, but I think it was too complex and got replaced because I can’t find it again

This is what my server script looks like by the way.


-- Variables --

local Module = require(game.ServerScriptService.DataModule)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = game.ReplicatedStorage.Practice
local Remote2 = game.ReplicatedStorage.Practice2



-- Functions --

-- Script

Players.PlayerAdded:Connect(function(Player)
	local PlayerID = Player.UserId

	local StatData = {Strength = 1, Speed = 2}
	Module.AddPlayer(PlayerID,StatData)
end)

Players.PlayerRemoving:Connect(function(Player)
	local PlayerID = Player.UserId
	Module.RemovePlayer(PlayerID)
end)

-- This Remote will print out the user's current Data.
Remote.OnServerEvent:Connect(function(Player)
	local PlayerID = Player.UserId
local StatData = Module.ReturnData(PlayerID)
print(StatData)
end)

-- This Remote will raise the user's current strength by one.
Remote2.OnServerEvent:Connect(function(Player)
	local PlayerID = Player.UserId
	local StatData = Module.ReturnData(PlayerID)
	 

end)

You can just set it like a variable I thought:

Module.WhateverDataYouWantToChange = NewChange
1 Like

Thank you, I didn’t know that if you just updated it in the server it automatically changed the ModuleScript.

I’m confused as to how that works, but it does, I thought you’d have to put return somewhere or something.

I’m really bad at using returning