How to access the same table from any script?

I’m working on a keybinds system that allows the player to change their keybinds. The problem is that I want to access these same keybinds that the player has set all across my client scripts. So first, I thought of using a moduleScript, but then I realized that if a player changes a value in the moduleScript with a table then how will I get it to update across all my scripts? It will only change for that one script?

local KeybindModule = require(Your keybind module that has a table with all the keycodes)
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Key, Processed)
if not Processed then
if Key.KeyCode == KeybindModule.Keybinds.Whateveractionuwant then
dostuff()
end
end
end)
Module script =
local Module = {Keybinds = {}}

function Module:SetKeybind(KeyToSet, NewKey) -- for example if you want to have functions aswell as keybinds
Module.Keybinds[KeyToSet] = NewKey -- this will change the key so when you get it from another script it will be the key you set
end

return Module
1 Like

This would work, but what if it interferes with other players requiring the module? what if they require the module with the keybinds changed? Is that how ModuleScripts work or am I wrong

Logically it should only be required by a localscript and all changes done to the module with a localscript will only affect your client

1 Like

Okay, so basically I’m assuming that every client has their own “version” of the moduleScript itself right? (When you are accessing and editing it on client)

Yup every require() call has their own version, unless required on the server

1 Like

Thank you so much for your help

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