local settings = require(script.Parent)
local gun = script.Parent.Parent.Parent
local debounce = false
local firing = false
local equipped = false
local aiming = false
local Damage = settings.Damage
local Range = settings.Range
local Firerate = settings.Firerate
local HeadshotDamage = settings.HeadShot
local BulletsPerShot = settings.Bullets
local Automatic = settings.Auto
local Ammo = settings.Ammo
local Reloadtime = settings.ReloadTime
local AimConnection
local normalFOV = 70 – Default FOV
local aimFOV = 50 – FOV when aiming
script.Parent.Parent.Parent.Equipped:Connect(function()
equipped = true
local UIS = game:GetService(“UserInputService”)
UIS.MouseIconEnabled = false
end)
script.Parent.Parent.Parent.Unequipped:Connect(function()
equipped = false
firing = false
aiming = false
local UIS = game:GetService(“UserInputService”)
UIS.MouseIconEnabled = true
-- Reset camera to normal settings
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
camera.FieldOfView = normalFOV
end)
function fire()
while firing and equipped do
gun.FireEvent:FireServer(game.Players.LocalPlayer:GetMouse().Hit.Position)
wait(Firerate)
end
end
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
if equipped and not firing then
if Automatic then
firing = true
fire()
else
if not debounce then
gun.FireEvent:FireServer(game.Players.LocalPlayer:GetMouse().Hit.Position)
debounce = true
task.wait(Firerate)
debounce = false
end
end
end
end)
game.Players.LocalPlayer:GetMouse().Button1Up:Connect(function()
firing = false
end)
– Handle right-click to aim
game.Players.LocalPlayer:GetMouse().Button2Down:Connect(function()
if equipped and not aiming then
aiming = true
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
camera.FieldOfView = aimFOV – Set the field of view for aiming
AimConnection = game:GetService("RunService").RenderStepped:Connect(function()
local aimPart = gun.Handle:WaitForChild("Aim")
local player = game.Players.LocalPlayer
local mousePosition = player:GetMouse().Hit.Position
-- Get the direction towards the mouse
local direction = (mousePosition - aimPart.Position).unit
-- Set the camera CFrame to look at the aim position and follow the player's view
camera.CFrame = CFrame.new(aimPart.Position + direction * 2, aimPart.Position) -- Adjust distance from aim part
end)
end
end)
game.Players.LocalPlayer:GetMouse().Button2Up:Connect(function()
if equipped and aiming then
aiming = false
if AimConnection then
AimConnection:Disconnect()
AimConnection = nil
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
camera.FieldOfView = normalFOV -- Reset to normal FOV
end
end
end)
it kinda just spins and doesnt even properly aim at the aim part in the handle of the gun