Hey, I'm making an FPS and I've gotten rid of the default backpack in favour of weapons slots corresponding to keys on the Number Line. My Idea is that if you press 1 you select your primary and if you press 2 you select your sidearm; alternatively, if you press said key with the weapon already selected you can unequip to move faster.
Unfortunately, my script breaks upon two "if" statements
if inputObject.KeyCode == Enum.KeyCode.One then
---CODE for PRIMARY
elseif inputObject.KeyCode == Enum.KeyCode.Two then
--CODE for SIDEARM
else ---Attempt at nil debounce
end
and
if player.ClassInfo.ClassValue.Value == 1 then
---EQUIP PRIMARY
else ---Attempt at nil debounce
end
If anyone can help me I would really appreciate it, I'm new to lua but I understanding programming reasonably well so I know it works if I only have one Input but I would rather use one consilidated system for weapon selection. Thanks
Full Code Here
-- Make variables for the local player and ContextActionService
local player = game.Players.LocalPlayer
equippedPri = true
equippedSec = false
function onKeyPress(inputObject, gameProcessedEvent)
--PRIMARY
if inputObject.KeyCode == Enum.KeyCode.One then
if player.ClassInfo.ClassValue.Value == 1 then
if game.Players.LocalPlayer.Team == "BLUFOR" then
if equippedPri == false then
player.Character.Humanoid:UnequipTools()
local gun = player.Backpack["M32 Carbine w/ Holo Sight"]
player.Character.Humanoid:EquipTool(gun)
equippedPri = true
equippedSec = false
elseif equippedPri == true then
local gun = player.Character["M32 Carbine w/ Holo Sight"]
player.Character.Humanoid:UnequipTools()
equippedPri = false
end
end
else --Attempt at nil debounce
end
--SECONDARY
elseif inputObject.KeyCode == Enum.KeyCode.Two then
if game.Players.LocalPlayer.Team == "BLUFOR" then
if equippedSec == false then
player.Character.Humanoid:UnequipTools()
local gun = player.Backpack["P83"]
player.Character.Humanoid:EquipTool(gun)
equippedPri = false
equippedSec = true
elseif equippedSec == true then
local gun = player.Character["P83"]
player.Character.Humanoid:UnequipTools()
equippedSec = false
end
end
else --Attempt at nil debounce
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
