I have a function that does reload on inputbegan key R. But it doesnt work.
UIS.InputBegan:Connect(function(key, gameproccessed)
print("key worked")
if key == Enum.KeyCode.R and gameproccessed == false and Enabled == true then
ShootEnabled = false
print("Reload")
script.Parent.Action:FireServer("Reload")
wait(Config.SFX.Reload.TimeLength/2)
CA = 0
wait(Config.SFX.Reload.TimeLength/2)
CA = APM
MM = MM - 1
end
end)
CA is current ammo
MM is max mags
APM is ammo per mag
Enabled is true on equipped, false on unequip.
I tried even setting it to JUST check if key is R but it still does not work\
I recommend using ContextActionService over UserInputService. It has better control. Here is how you would rewrite the script.
local CAS = game:GetService("ContextActionService")
CAS:BindAction("Reload", function(actionName, userInputState, inputObject)
print("key worked")
if key == Enum.KeyCode.R and Enabled == true then
ShootEnabled = false
print("Reload")
script.Parent.Action:FireServer("Reload")
wait(Config.SFX.Reload.TimeLength/2)
CA = 0
wait(Config.SFX.Reload.TimeLength/2)
CA = APM
MM = MM - 1
end
end, false, Enum.KeyCode.R)
local CAS = game:GetService("ContextActionService")
CAS:BindAction("Reload", function(actionName, userInputState, inputObject)
print("key worked")
if key == Enum.KeyCode.R and userInputState == Enum.UserInputState.Begin and Enabled == true then
ShootEnabled = false
print("Reload")
script.Parent.Action:FireServer("Reload")
wait(Config.SFX.Reload.TimeLength/2)
CA = 0
wait(Config.SFX.Reload.TimeLength/2)
CA = APM
MM = MM - 1
end
end, false, Enum.KeyCode.R)