Can two server scripts change the content of a common table stored in a module script?
I’m asking this because i Have a remote Function that Changes the content of the Global Table that contains all the players. When the Remote Function Is Fired the server goes to the Global table and changes the content according to the id of the player, but for some reason the content is not changed correctly.
–ModuleScript–
local module = {}
module.__index = module
local Global = {}
function module:InsertPlayer(id)
if Global[id] == nil then
Global[id] = {}
table.insert(Global[id], {["Alive"] = true, ["Anims"] = false })
else
error("there already exists a player named :"..id )
end
end
function module:ChangeState(id : number, state : string, value: boolean) -- this function only allows one value to be true
if Global[id] ~= nil then
for i, v in pairs(Global[id][1]) do
if i == "Q" then
else
Global[id][1][i] = false
-- print(Global[id][1])
end
end
Global[id][1][state] = value
--print(Global[id][1])
else
error(id .." does not exist")
end
end
Unless the table is exposed by returning it within the module table itself, no one can modify it. Unless you make a function that’s exposed to other scripts allowing them to set values to it. You can have control over that though so I don’t see a problem with that.
The server can have a copy of the Table trough module:GetPlayerData() and can change trough module:ChangeState(). but for some reason when I test the game with two players the content of the tables seems to not agree with each other making somethings what is supposed to happen on player A, happen on player B
no, its all on the server.
Does the code inside a Remote Function run kind of locally?
I change the values of the table inside a Remote function.
The player parsed in the function is then used to access the correct part of the table.
but for some reason when I try to read other player’s table content it seems to be wrong and sometimes equal to my player’s table contents.
Yes
In a local script a Remote Function Can be Called
The server Picks up the request and changes the content of a global table stored in a module script.
For some reason when , for example Player A fires the event and tries to read the other players values
the values are wrong.
If the data is being read on the server, then it should have no problems reading it.
Are you sure it’s on the same context level? You’re not trying to read the module from the client after setting it on the server?