Help with module sharing

ok, so, i tried to make a match framework, a framework which could allow me to easily create gamemodes and match modifiers, but there is a little problem
the values dont share between the base code and it’s proxies!
it sets the gamemodes and modifier’s behaviors using proxies, basically, it replace it’s own functions with the proxy’s version, and resets it with a backup snapshot after a match is done

so, here are the proxy setup functions

function match:setGamemodeProxy(gamemodeModule : ModuleScript)
	assert(gamemodeModule and typeof(gamemodeModule) == "Instance" and gamemodeModule:IsA("ModuleScript"), "Invalid gamemodeModule provided.")
	local tab = require(gamemodeModule)

	local newCode = copy(matchRedundancyBackup)

	for index, v in pairs(tab) do
		if newCode[index] then
			if typeof(newCode[index]) == typeof(v) then
				newCode[index] = v
				warn(`overwrote {index}`)
			else
				warn(`Type mismatch for {index}, keeping original function.`)
			end
		else
			newCode[index] = v
			warn(`overwrote {index}`)
		end
	end

	for i, v in pairs(newCode) do
		match[i] = v
	end
end

function match:setModifierProxy(modifierModule : ModuleScript)
	assert(modifierModule and typeof(modifierModule) == "Instance" and modifierModule:IsA("ModuleScript"), "Invalid gamemodeModule provided.")
	local tab = require(modifierModule) 

	local newCode = copy(modifierRedundancyBackup)

	for index, v in pairs(tab) do
		if newCode[index] then
			if typeof(newCode[index]) == typeof(v) then
				newCode[index] = v
				warn(`overwrote {index}`)
			else
				warn(`Type mismatch for {index}, keeping original function.`)
			end
		else
			newCode[index] = v
			warn(`overwrote {index}`)
		end
	end

	for i, v in pairs(newCode) do
		modifier[i] = v
	end
end

and here’s a gamemode module (team deathmatch as example)

local matchFramework = require(script.Parent.Parent:WaitForChild("Match framework"))
local gamemode = {
	winScore = 50,
	timeRemaining = 5 * 60
}

function gamemode.onKill(victim : Player, killer : Player)
	
	warn('kill received!')
	warn(matchFramework.getState())
	
	local state = matchFramework.getState()
	
	if not (state == matchFramework.matchStates.Running or state == matchFramework.matchStates.Overtime) then return end
	print(killer)
	
	local team = killer.Team.Name
	matchFramework.teamScores[team] += 1
	warn(matchFramework.teamScores)
end

return gamemode

it looks like it should work, right?, well, the winscore and the time remaining really are succesfully changed due to the proxy system, but then after i score a kill, this is what gets outputted…
team deathmatch print:

{
     ["Blue"] = 1,
     ["Red"] = 0
}

…base framework print

{
     ["Blue"] = 0,
     ["Red"] = 0
}

aka, the values arent being updated on the main module! any help?

1 Like