Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tool = script.Parent.Parent
- local player = game:GetService("Players").LocalPlayer
- local mouse = player:GetMouse()
- local hole = tool:WaitForChild("Hole")
- local handle = tool:WaitForChild("Handle")
- local UIS = game:GetService("UserInputService")
- local RS = game:GetService("RunService");
- local TS = game:GetService("TweenService")
- local mouseDown = false
- local equipped = false
- local reloading = false
- local oldIcon = mouse.Icon
- local sprinting = false
- local relDeb = false
- local flash = hole.FlashGui
- local lastShot = tick()
- local animations = tool:WaitForChild("Animations")
- local configs = tool:WaitForChild("Configs")
- local remotes = tool:WaitForChild("Remotes")
- local holdAnim = animations:WaitForChild("Hold")
- local sprintAnim = animations:WaitForChild("Sprint")
- local reloadAnim = animations:WaitForChild("Reload")
- local holdTrack
- local sprintTrack
- local reloadTrack
- local allowTracing = configs:WaitForChild("AllowTracing")
- local range = configs:WaitForChild("Range")
- local configs = tool:WaitForChild("Configs")
- local remotes = tool:WaitForChild("Remotes")
- local ammo = configs:WaitForChild("Ammo")
- local reserveAmmo = configs:WaitForChild("ReserveAmmo")
- local magSize = configs:WaitForChild("MagSize")
- local damage = configs:WaitForChild("Damage")
- local fireRate = configs:WaitForChild("FireRate")
- local range = configs:WaitForChild("Range")
- local reloadTime = configs:WaitForChild("ReloadTime")
- local canShootRemote = remotes:WaitForChild("CanShoot")
- local canReloadRemote = remotes:WaitForChild("CanReload")
- local reloadRemote = remotes:WaitForChild("Reload")
- local hitRemote = remotes:WaitForChild("Hit")
- local shootRemote = remotes:WaitForChild("Shoot")
- local traceRemote = remotes:WaitForChild("Trace")
- local andagain = remotes:WaitForChild("andbackagain")
- local emptySound = handle:WaitForChild("EmptySound")
- local reloadSound = handle:WaitForChild("ReloadSound")
- local shootSound = handle:WaitForChild("ShootSound")
- local function equip()
- equipped = true
- local oldIcon = mouse.Icon
- mouse.Icon = "rbxassetid://4247417907"
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- if humanoid then
- pcall(function()
- holdTrack = humanoid:LoadAnimation(holdAnim)
- holdTrack:Play()
- end)
- pcall(function()
- sprintTrack = humanoid:LoadAnimation(sprintAnim)
- end)
- end
- end
- local function canReload(plr)
- if ammo.Value < magSize.Value then
- if reserveAmmo.Value > 0 then
- if not reloading then
- if equipped then
- return true
- end
- end
- end
- end
- return false
- end
- local function sprint(actionName, inputState, inputObj)
- if equipped == false then return false end
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- sprintTrack:Play()
- holdTrack:Stop()
- humanoid.WalkSpeed = 30
- sprinting = true
- end
- local function stopSprinting()
- if equipped == false then return false end
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- sprintTrack:Stop()
- holdTrack:Play()
- humanoid.WalkSpeed = 16
- sprinting = false
- end
- local function canShoot(plr, playSound)
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- if math.abs(lastShot - tick()) > (60/fireRate.Value) then
- if not reloading then
- if equipped then
- if ammo.Value > 0 then
- if sprinting == false then
- if humanoid.Health > 0 then
- return true
- else
- if playSound then emptySound.Playing = true end
- end
- end
- end
- end
- end
- end
- return false
- end
- local function unequip()
- wait(.1)
- equipped = false
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- sprinting = false
- humanoid.WalkSpeed = 16
- mouse.Icon = oldIcon
- if holdTrack then
- holdTrack:Stop()
- end
- if sprintTrack then
- sprintTrack:Stop()
- end
- end
- local function reload(plr)
- if not canReload() then return end
- reloading = true
- reloadSound:Play()
- ammo.Value = "REL"
- if reserveAmmo.Value < 0 then
- ammo.Value = ammo.Value + reserveAmmo.Value
- reserveAmmo.Value = 0
- end
- wait(reloadTime.Value + .1)
- local needed = magSize.Value - ammo.Value
- reserveAmmo.Value = reserveAmmo.Value - needed
- ammo.Value = magSize.Value
- reloading = false
- end
- local function shoot()
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- if humanoid.Health >= 0 then
- if not canShoot(player, true) then return end
- lastShot = tick()
- ammo.Value = ammo.Value - 1
- end
- end
- local function fire()
- if wait() then
- if not canShoot(player, false) then return end
- local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value)
- local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true)
- if touch then
- hitRemote:FireServer(touch)
- end
- shoot()
- traceRemote:FireServer(position)
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local Origin = hole.CFrame.p
- local trace1 = Instance.new("Part")
- trace1.CanCollide = false
- trace1.BrickColor = BrickColor.new("Cyan")
- trace1.Material = Enum.Material.Neon
- trace1.CFrame = CFrame.new(hole.CFrame.p, position)
- local distance1 = (hole.CFrame.p - position).magnitude
- local speed = 125
- local TIME = (hole.CFrame.p - mouse.Hit.p).Magnitude / speed
- local tweenI = TweenInfo.new(TIME, Enum.EasingStyle.Linear)
- local tweenT = {Position = mouse.Hit.p}
- local tweenC = TS:Create(trace1, tweenI, tweenT)
- trace1.Size = Vector3.new(.2, .2, 2.5)
- trace1.Parent = workspace
- tweenC:Play()
- tweenC.Completed:Connect(function()
- trace1:Destroy()
- end)
- game:GetService("Debris"):AddItem(trace1,30)
- end
- end
- mouse.Move:Connect(function()
- if not equipped then return end
- if mouse.Target then
- if game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then
- mouse.Icon = "rbxassetid://4248522206"
- elseif game.Players:GetPlayerFromCharacter(mouse.Target.Parent.Parent) then
- mouse.Icon = "rbxassetid://4248522206"
- else
- mouse.Icon = "rbxassetid://4247417907"
- end
- end
- end)
- tool.Equipped:Connect(function()
- equip()
- mouse.Button1Up:Connect(function()
- mouseDown = false
- end)
- tool.Activated:Connect(function()
- mouseDown = true
- repeat
- fire()
- until not mouseDown
- end)
- end)
- tool.Unequipped:Connect(unequip)
- wait(.1)
- UIS.InputBegan:Connect(function(inp)
- local keyCode = inp.KeyCode
- if keyCode == Enum.KeyCode.R then
- reload()
- end
- if keyCode == Enum.KeyCode.LeftShift then
- sprint()
- end
- end)
- UIS.InputEnded:Connect(function(inp)
- local keyCode = inp.KeyCode
- if keyCode == Enum.KeyCode.LeftShift then
- stopSprinting()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement