Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --//Updated Script
- --//Variables
- local plr = game.Players.LocalPlayer
- local tool = script.Parent.Parent
- local hole = tool.Hole
- local handle = tool.Handle
- local debounce = true
- local config = tool.Config
- local range = config.Range
- local dmg = config.Damage
- local coolDown = config.CoolDown
- local clips = config.Clips
- local ammo = config.Ammo
- local maxAmmo = config.MaxAmmo
- local allowTracing = config.AllowTracing
- local reloadTime = config.ReloadTime
- local isReloading = false
- --//Events
- tool.Equipped:connect(function(mouse)
- tool.Activated:connect(function()
- if not isReloading then
- if ammo.Value > 0 then
- if debounce then
- --//Doesn't allow spamming
- debounce = false
- --//Ray Get, Set
- local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p) * range.Value)
- local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
- --//Bullet Tracing
- if allowTracing.Value == true then
- --//Make part
- local trace = Instance.new("Part", workspace)
- trace.Material = Enum.Material.Neon
- trace.BrickColor = BrickColor.new("Black")
- trace.CanCollide = false
- trace.Anchored = true
- trace.Transparency = 0.5
- --//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 debris
- game:GetService("Debris"):AddItem(trace, 0.1)
- end
- --//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
- ammo.Value = ammo.Value - 1
- wait(coolDown.Value)
- debounce = true
- end
- else
- --//Out of ammo
- end
- end
- end)
- --//Reload Event
- mouse.KeyDown:connect(function(key)
- key:lower()
- if key == "r" then
- if not isReloading then
- if clips.Value > 0 then
- isReloading = true
- ammo.Value = maxAmmo.Value
- clips.Value = clips.Value - 1
- wait(reloadTime.Value)
- isReloading = false
- end
- end
- end
- end)
- end)
- --LocalScript In the scripts folder
- repeat wait() until game.Players.LocalPlayer.PlayerGui.AmmoGui.Display
- --//Variables
- local plr = game.Players.LocalPlayer
- local tool = script.Parent.Parent
- local config = tool.Config
- local ammo = config.Ammo
- local clips = config.Clips
- local display = plr.PlayerGui.AmmoGui.Display
- --//Function(s)
- local function Update()
- display.Text = ammo.Value .. "/" .. clips.Value
- end
- --//Events
- tool.Activated:connect(Update)
- ammo.Changed:connect(Update)
- clips.Changed:connect(Update)
- tool.Equipped:connect(function()
- display.Visible = true
- Update()
- end)
- tool.Dequipped:connect(function()
- display.Visible = false
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement