Is there a way to edit info in a module script?

Module script:

local guns = {}

guns.list = {
	"AKM",
	"M79"
}

guns.currentGun = "AKM"

return guns

Script changing the module script: (local script)

local uis = game:GetService("UserInputService")
local rs = game.ReplicatedStorage
local guns = require(rs.Guns)

uis.InputBegan:Connect(function(input,process)
	if not process then
		
		if input.KeyCode == "1" then
			guns.currentGun = guns.list[1]
			print("changed current gun to "..guns.currentGun)
		end
		
		if input.KeyCode == "2" then
			guns.currentGun = guns.list[2]
			print("changed current gun to "..guns.currentGun)
		end
		
	end
end)

This doesn’t work, but is there a way to fix it, or is there a different way to change info in a module script? I’m trying to change the current gun.

In what way does it not work? Does the value ever change in that current script? Are you only accessing it in LocalScripts?

It doesn’t print when I press 1 or 2. I’ve tried doing this locally and on the server, neither method works.

Use if input.KeyCode == Enum.KeyCode.One then / if input.KeyCode == Enum.KeyCode.Two then.

Using "1" / "2" for comparison will not match the 1 or 2 key on your keyboard.

3 Likes

Nevermind this statement, it works just not on the server. Thank you for your help.

1 Like