I'm trying to make a script so you can change your keybinds, and for the most part it's been pretty smooth, however it keeps spitting out "attempt to index nil with 'Text'" in this section of code. All that section of the local script is supposed to do is change the text of the keybindButton, which is a TextButton, and that's in it's own dictionary as well to make things more organized. The keys for the keybindButtons are the exact same as the keys inside KeybindModule.defaultKeybinds. I don't really understand what's wrong here, and everything I've been doing leads to the same error. I only just learned how to manipulate dictionaries a few days ago, so maybe that's my problem lol
Module code:
-- These default keybinds are actually the values I have set -- KeybindModule.defaultKeybinds = { toggleInventory = "tab", invDropAll = "rightClick", invDropAmount = "leftClick", interact = "e", ping = "middleClick", weapon1 = "one", weapon2 = "two", weapon3 = "three", switchToGrenade = "g", switchToOrdinance = "q", melee = "f", crouch = "c", prone = "leftControl", sprint = "leftShift", shoot = "leftClick", aim = "rightClick", reload = "r", changeFireMode = "v", weaponSpecial = "t" } function KeybindModule.getAllKeybinds(player) local playerSettings = PlayerData:WaitForChild(player.UserId):WaitForChild("_settings") local returningDictionary = {} for i, v in pairs(playerSettings:WaitForChild("keybinds"):GetChildren()) do returningDictionary[v.Name] = v.Value end return returningDictionary end
Local script code:
local keybinds = ControlModule.getAllKeybinds(player) for keybindKey, keybindValue in pairs(keybinds) do if keybindValue == nil or keybindKey == nil then keybindButtons[keybindKey].Text = string.upper(ControlModule.defaultKeybinds[keybindKey]) else keybindButtons[keybindKey].Text = string.upper(keybindValue) end end
Any help is greatly appreciated.
I've figured it out upon going back through it. Turns out I used different variable names in a different script. It works almost flawlessly now.