If you use 3 guns and shoot like once, unequip all and click r all 3 guns reload at the same time.
local gun = script.Parent
local gun_shot = gun:WaitForChild('Handle').gunshot
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('AK47ShootEvent')
local shooting = false
local equipped = false
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local reloadsound = gun.Handle:WaitForChild('Reload')
local emptyclipsound = gun.Handle:WaitForChild('emptyClip')
local fire = gun:WaitForChild('Handle').gunshot
local clipSize = gun.Ammo.Value
local ammo = gun.Ammo
local UIS = game:GetService('UserInputService')
-- remote event
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild('PistolShootEvent')
local ammoEvent = ReplicatedStorage:WaitForChild('AmmoPickup')
-- update ammo function
local function update_ammo()
player.PlayerGui.AmmoGUI.Ammo.Text = 'Ammo: ' ..tostring(ammo.Value)..' / '..tostring(gun.MaxAmmo.Value)
end
local mouseConnection
-- checks if mouse is clicked
gun.Equipped:Connect(function()
mouse.Icon = "rbxassetid://117431027"
player.PlayerGui.AmmoGUI.Ammo.Visible = true
update_ammo()
equipped = true
mouse.Icon = 'rbxassetid://117431027'
mouseConnection = mouse.Button1Down:Connect(function()
shooting = true
while shooting and equipped and gun.Ammo.Value > 0 do
local Ammo = gun:WaitForChild('Ammo').Value
remoteEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)
gun_shot:Play()
gun.Ammo.Value = gun.Ammo.Value - 1
mouse.Button1Up:Connect(function()
shooting = false
if gun.Ammo.Value == 0 then
emptyclipsound:Play()
end
end)
wait(0.1)
end
end)
end)
gun.Unequipped:Connect(function()
equipped = false
mouseConnection:Disconnect()
end)
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
--Unequip gun
gun.Unequipped:Connect(function()
player:FindFirstChild('PlayerGui').AmmoGUI.Ammo.Visible = false
mouse.Icon = "rbxassetid://117431027"
end)
-- checks if reload
UIS.InputBegan:Connect(function(input, gameprocessed)
if not gameprocessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R then
if gun.Ammo.Value < clipSize and gun.MaxAmmo.Value > 0 and gun.Equipped then
reloadsound:Play()
reloadsound.Ended:Wait()
if gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value) >= 0 then
gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value)
gun.Ammo.Value = clipSize
else
gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
gun.MaxAmmo.Value = 0
update_ammo()
end
end
end
end
end
end)
-- update ammo gui
ammo.Changed:Connect(update_ammo)
ammoEvent.OnClientEvent:Connect(function()
gun.MaxAmmo.Value = gun.MaxAmmo.Value + 50
update_ammo()
end)
-- local unequip gun
local function gunUnequipped()
if gun.Unequipped and gun.Parent:IsA('Backpack')then
while true do
wait(1)
if gun.Equipped then
break
end
end
end
end
ammoEvent.OnClientEvent:Connect(function()
player.GrenadeAmmo.Value = player.GrenadeAmmo.Value + 1
end)
https://cdn.discordapp.com/attachments/822790702651670529/830332258917285919/2021-04-10_14-17-53.mp4