Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Pressing LMB reloads gun?

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

✓ Accepted answer

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.

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.