I tried to get table [“name”] when a input is pressed and it seems it always returns nil
--Keys Module
local Keys = {
["Gauntlets of Fate"] = {
["Z"] = {
Slot = "LightHit",
Name = "LightPunch",
Cooldown = 1,
},
["X"] = {
Slot = "HeavyHit",
Name = "HeavyPunch",
Cooldown = 5,
},
},
}
--Global Script
game.ReplicatedStorage.Remotes.CombatRemote.OnServerEvent:Connect(function(Player, pressedKey)
local Character = Player.Character
local HRP = Character["HumanoidRootPart"]
local Data = Player:WaitForChild("Data")
local Class = Data:FindFirstChild("Class").Value
if KeysModule[Class] then
local KeyInQuestion = KeysModule[Class][pressedKey]
print(KeyInQuestion["Name"])
end
end)
It’s hard to tell with this formatting but it looks like you might be returning {Keys = {…}} which would mean you’d have to access it by doing KeyModule.Keys[Name].
Edit: Try printing KeyModule.Keys and see if it spits out a table.
local UIs = game:GetService("UserInputService")
local CombatRemote = game.ReplicatedStorage.Remotes.CombatRemote
UIs.InputBegan:Connect(function(input, gameprocessed)
if gameprocessed then return end
CombatRemote:FireServer(input)
end)
I see your problem and I was correct. So the input parameter is not the direct key that was pressed. Its a separate class entirely. In order to achieve what you want, you’ll need to do input.KeyCode as that will return the keycode of the pressed key. You may have to use tostring() on the input.KeyCode if you are comparing it to a string. (because it will return an Enum value and your table has strings as a dictionary)
Why is it like this? Well UserInputService actually tracks all of the inputs from a client (mouse clicks, controller move, etc). InputObjects store all of that neatly into a single object that you can access in one function.
If the “Keys” table is within your module, and you’re trying to access it within a script, it must look like: (unless you mean Dictionary, not Module, which by the looks of you not requiring anything you probably do mean Dictionary)
local Keys = {
-- everything in here
}
return Keys
and your LocalScript should also look like:
local UIs = game:GetService("UserInputService")
local CombatRemote = game.ReplicatedStorage.Remotes.CombatRemote
UIs.InputBegan:Connect(function(input, gameprocessed)
if gameprocessed then return end
CombatRemote:FireServer(input.KeyCode)
end)
If this doesn’t work, let me know, I haven’t tested, but as far as I’m aware this should be right.