Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --//Local Script Inside folder
- --//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
- --//Events
- tool.Equipped:connect(function(mouse)
- tool.Activated:connect(function()
- 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
- wait(coolDown.Value)
- debounce = true
- end
- end)
- end)
- --//Weld script inside folder if gun parts all apart
- local tool = script.Parent.Parent
- function Weld(x,y)
- local W = Instance.new("Weld")
- W.Part0 = x
- W.Part1 = y
- local CJ = CFrame.new(x.Position)
- local C0 = x.CFrame:inverse()*CJ
- local C1 = y.CFrame:inverse()*CJ
- W.C0 = C0
- W.C1 = C1
- W.Parent = x
- end
- function Get(A)
- if A.className == "Part" then
- Weld(tool.Handle, A)
- A.Anchored = false
- else
- local C = A:GetChildren()
- for i=1, #C do
- Get(C[i])
- end
- end
- end
- function Finale()
- Get(tool)
- end
- tool.Equipped:connect(Finale)
- tool.Unequipped:connect(Finale)
- Finale()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement