Hi! I’m trying to make a fighting game with skill movesets and I’m running into a problem where whenever I press an input, all the 4 skills are called in at once (shown by the output when I print them)
Does anyone know why this is happening? I want it to whenever I press 1,2,3, or 4 it will call to the corresponding skill and not all of them at once.
This is the code:
local skillButtons = {
Enum.KeyCode.One,
Enum.KeyCode.Two,
Enum.KeyCode.Three,
Enum.KeyCode.Four,
}
local currentSkillIndex = 0
local function activateSkill(skillIndex)
for i, skillButton in ipairs(skillButtons) do
local isActivated = (i == skillIndex)
print("Skill" .. i) --// Prints which skill I have just equipped
end
end
UserInputService.InputBegan:Connect(function(key)
for i, skillButton in ipairs(skillButtons) do
if key.KeyCode == skillButton then
if currentSkillIndex ~= i then
currentSkillIndex = i
activateSkill(currentSkillIndex)
elseif currentSkillIndex == i then
currentSkillIndex = 0
activateSkill(currentSkillIndex)
end
break
end
end
end)