Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --//Variables
- local plr = game.Players.LocalPlayer
- local tool = script.Parent.Parent
- local hole = tool:WaitForChild("Hole")
- local handle = tool:WaitForChild("Handle")
- local debounce = true
- local config = tool:WaitForChild("Config")
- local range = config:WaitForChild("Range")
- local dmg = config:WaitForChild("Damage")
- local coolDown = config:WaitForChild("CoolDown")
- local clips = config:WaitForChild("Clips")
- local ammo = config:WaitForChild("Ammo")
- local maxAmmo = config:WaitForChild("MaxAmmo")
- local allowTracing = config:WaitForChild("AllowTracing")
- local reloadTime = config:WaitForChild("ReloadTime")
- local NumOfBullets = config:WaitForChild("NumOfBullets")
- local radius = config:WaitForChild("Radius")
- local Rays = {}
- local isReloading = false
- --//Sounds
- local reloadSound = handle:WaitForChild("ReloadSound")
- local fireSound = handle:WaitForChild("FireSound")
- local equipSound = handle:WaitForChild("EquipSound")
- local emptySound = handle:WaitForChild("EmptySound")
- --//Animations
- repeat wait() until plr.Character.Humanoid
- local AnimFolder = script.Parent.Parent:WaitForChild("Animations")
- local ReloadTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolReload"))
- local AimTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolAim"))
- local HoldTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolHold"))
- AimTrack.Looped = true
- HoldTrack.Looped = true
- --//Events
- tool.Equipped:connect(function(mouse)
- equipSound:Play()
- HoldTrack:Play()
- mouse.KeyDown:connect(function(Key)
- if Key:lower() == "q" then
- workspace.CurrentCamera.FieldOfView = 60
- AimTrack:Play()
- end
- end)
- mouse.KeyUp:connect(function(Key)
- if Key:lower() == "q" then
- workspace.CurrentCamera.FieldOfView = 70
- AimTrack:Stop()
- end
- end)
- mouse.Button1Down:connect(function()
- if debounce then
- Shoot()
- end
- end)
- --//Reload Event
- mouse.KeyDown:connect(function(key)
- if key:lower() == "r" then
- if not isReloading then
- if clips.Value > 0 then
- ReloadTrack:Play()
- reloadSound:Play()
- isReloading = true
- ammo.Value = maxAmmo.Value
- clips.Value = clips.Value - 1
- debounce = false
- wait(reloadTime.Value)
- isReloading = false
- debounce = true
- end
- end
- end
- end)
- function Shoot()
- if not isReloading then
- if ammo.Value > 0 then
- if debounce then
- --//Play sound
- fireSound:Play()
- --//Doesn't allow spamming
- debounce = false
- for i=1, NumOfBullets.Value do
- --//Ray Get, Set
- local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p + Vector3.new(math.random(-radius.Value, radius.Value), math.random(-radius.Value, radius.Value), 0)) * range.Value)
- table.insert(Rays, ray)
- end
- --//Bullet Tracing
- if allowTracing.Value == true then
- for i, RayPart in pairs(Rays) do
- --//Make part
- local trace = Instance.new("Part", workspace)
- trace.Material = Enum.Material.Neon
- trace.BrickColor = BrickColor.new("New Yeller")
- trace.CanCollide = false
- trace.Anchored = true
- trace.Transparency = 0.5
- --//Position Getting\\--
- local hit, position = workspace:FindPartOnRay(RayPart, plr.Character, false, true)
- --//Show Direction
- local distance = (hole.CFrame.p - position).magnitude
- trace.Size = Vector3.new(0.2, 0.2, distance)
- trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
- --//Remove Tracings\\--
- game:GetService("Debris"):AddItem(trace, 0.1)
- end
- end
- for i, RayPart in pairs(Rays) do
- --//Hit Getting\\--
- local hit = workspace:FindPartOnRay(RayPart, plr.Character, false, true)
- --//Hit Detection
- if hit then
- local humanoid = hit.Parent:FindFirstChild("Humanoid")
- if humanoid then
- if hit.Name == "Head" then
- --//Double damage on headshots
- humanoid:TakeDamage(dmg.Value*2)
- else
- --//Normal Damage on body shots
- humanoid:TakeDamage(dmg.Value)
- end
- end
- end
- end
- wait(coolDown.Value)
- ammo.Value = ammo.Value - 1
- for i=NumOfBullets.Value, 1, -1 do
- table.remove(Rays, i)
- end
- debounce = true
- end
- else
- --//Out of ammo
- emptySound:Play()
- debounce = false
- end
- end
- end
- end)
- tool.Unequipped:connect(function()
- AimTrack:Stop()
- HoldTrack:Stop()
- ReloadTrack:Stop()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement