Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pressing LMB reloads gun?

Asked by
exarlus 72
5 years ago

Whenever you press LMB it reloads the gun... but I only want the R button to reload the gun instead. How would I do this?

For Testing Purposes:

1) Make a tool and put it in starterpack.

2) Make a part in the tool and name it "Handle"

3)Put a RemoteEvent in the tool and name it "Damage"

localscript:

local MaxAmmo = 5
local Ammo = MaxAmmo
local Reloading = false
script.Parent.Equipped:Connect(function(Mouse)
    Mouse.Icon = "rbxasset://textures/GunCursor.png"
    local function Reload()
        Reloading = true
            Mouse.Icon = "rbxasset://textures/GunCursor.png"
            wait(2)
            Ammo = MaxAmmo
            Reloading = false
            Mouse.Icon = "rbxasset://textures/GunCursor.png"
    end
    script.Parent.Activated:Connect(function()
        if Ammo>0 and not Reloading then
            Ammo=Ammo-1 
            if Mouse.Target.Parent:FindFirstChild("Humanoid") then
                script.Parent.Damage:FireServer(Mouse.Target.Parent, 20)
            end 
            elseif Reloading ==  false then
            Reload()
        end
        print(Ammo)
    end)
  local Input = game:GetService("UserInputService")
Input.InputBegan:Connect(function(Key)
    if Key.KeyCode == Enum.KeyCode.R and Reloading == false and Ammo~=MaxAmmo then
    Reload()
        end

end)
end)

serverscript:

script.Parent.Damage.OnServerEvent:Connect(function(Player, Target, Damage)
    Target.Humanoid:TakeDamage(Damage)
end)

1 answer

Log in to vote
1
Answered by 5 years ago

If you delete

elseif Reloading ==  false then
    Reload()

it should work. Since this line occurs after the "if Ammo>0 and not Reloading" check, it is essentially making it so that if Ammo<=0 it runs Reload()

Apologies if there is anything wrong with my formatting, first time posting.

0
Thanks exarlus 72 — 5y
Ad

Answer this question