I don’t normally script like this but I’m trying to fix the pistol double shooting.
Client Script:
wait(game.Loaded)
local Settings = require(script.Parent)
--[[ Services ]]
local Players = game:GetService("Players")
local UserInputServices = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
--[[ Variables ]]
local Tool = script.Parent.Parent
local Parent = script.Parent
local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local Mouse = Player:GetMouse()
local Magazine = 30
local Magazine_Used = 0
local Ammo = 9999
Magazine = Settings.Max_Magazine
Ammo = Settings.Max_Ammo
local Events = Parent.Events
local Fire = Events.Fire
local Sounds = Parent.Sound
local Empty_Gun = Sounds.Empty_Gun
local Gun_Reload= Sounds.Gun_Reload
local Weapon_Hud= Tool["Weapon HUD"]
--[[ Recoil ]]
local camera = workspace.CurrentCamera
local random = Random.new()
local spread_amount = math.rad(5)
local recoil_amount = 0.05
local recoil_acc = CFrame.Angles(0, 0, 0)
local recoil_decay = 0.85
--[[ Key ]]
local KeyCode = Enum.KeyCode
local UserInputType = Enum.UserInputType
local Fire_Key = UserInputType.MouseButton1
local Reload_Key = KeyCode.R
local Aim_Key = UserInputType.MouseButton2
--[[ Boolean ]]
local Reload = false
local Held = false
local Shoot = false
--[[ Functions ]]
function ShootGun()
local shoot_cf = camera.CFrame * CFrame.Angles(
random:NextNumber(-recoil_amount, recoil_amount),
random:NextNumber(-recoil_amount, recoil_amount),
0
)
local shoot_ray = Ray.new(shoot_cf.p, shoot_cf.LookVector)
camera.CFrame = camera.CFrame * recoil_acc:inverse()
recoil_acc = recoil_acc * CFrame.Angles(recoil_amount, 0, 0)
camera.CFrame = camera.CFrame * recoil_acc
end
--[[ Main Code ]]
Tool.Equipped:Connect(function()
local Cloned_GUI = Weapon_Hud:Clone()
Cloned_GUI.Parent = Player.PlayerGui
UserInputServices.InputBegan:Connect(function(Input, GameProccessed)
if GameProccessed then return end
if Input.KeyCode == Reload_Key then
if Reload == false and Magazine < Settings.Max_Magazine then
Gun_Reload:Play()
Reload = true
wait(Settings.Reload_Cooldown)
Ammo -= Magazine_Used
Magazine_Used = 0
Magazine = Settings.Max_Magazine
Reload = false
end
end
end)
Mouse.Button1Down:Connect(function()
print("d")
if Magazine > 0 and not Reload and Character:FindFirstChild(Tool.Name) then
Fire:FireServer(Mouse.Hit.Position, Tool:FindFirstChild("Handle"))
Magazine -= 1
Magazine_Used +=1
ShootGun()
elseif Magazine == 0 then
Empty_Gun:Play()
end
wait(Settings.Fire_Per_Second)
end)
while true do
Cloned_GUI.Background.Magazine.Text = Magazine
Cloned_GUI.Background.Ammo.Text = Ammo
Cloned_GUI.Background.Gun_Name.Text = Tool.Name
wait()
end
end)
Tool.Unequipped:Connect(function()
local Find_GUI = Player.PlayerGui:FindFirstChild("Weapon HUD")
if Find_GUI then
Find_GUI:Destroy()
end
end)
RunService.RenderStepped:Connect(function(dt)
camera.CFrame = camera.CFrame * recoil_acc:inverse()
recoil_acc = recoil_acc:Lerp(CFrame.new(), recoil_decay * dt)
camera.CFrame = camera.CFrame * recoil_acc
end)