Unable to modify table in module script with function in module script

I’m not able to modify a table in a module script with a function in said module script. The function at it’s core sets both the key and value, but using table.insert works - however I need to set the key, here’s what I have at the moment.

Server Script

local module = require(script.Parent.ModuleScript)

print(#module.values) -- expected 0, got 0
module.Set("test", "yo")
print(#module.values) -- expected 1, got 0
print(module.values["test"]) -- expected "yo", got nil

Module Script

local module = {}
module.values = {}

function module:Set(key, value)
	module.values[key] = value
end

return module

Try module:Set when calling.

How to call functions in tables: Lua 5.1 Reference Manual

This worked, I was oblivious. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.