Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wait(1)
- --basic variables
- local tool = script.Parent
- local handle = script.Parent:WaitForChild('Handle')
- local model = script.Parent:WaitForChild('toolModel')
- local barrel = script.Parent:WaitForChild('Barrel')
- local camera = workspace.CurrentCamera
- --other essentials
- local rs = game:GetService('ReplicatedStorage'):WaitForChild('gunEvents')
- local sound = rs:WaitForChild('sound')
- local render = rs:WaitForChild('renderRay')
- local damageEvent = rs:WaitForChild('damage')
- local explodeEvent = rs:WaitForChild('explode')
- local errorHandler = rs:WaitForChild('errorHandler')
- local config = script.Parent:WaitForChild('config')
- --services
- local plrs = game:GetService('Players')
- local is = game:GetService('UserInputService')
- local run = game:GetService('RunService')
- --lol
- local plr = plrs.LocalPlayer
- local mouse = plr:GetMouse()
- local char = plr.Character or plr.CharacterAdded:Wait()
- local humanoid = char:WaitForChild('Humanoid')
- repeat wait() until humanoid:IsDescendantOf(workspace)
- --bools
- local sprint = false
- local crouching = false
- local reloading = false
- local equipped = false
- local canFire = true
- local mouseDown = false
- local scoping = false
- --config variables
- local spread = .5 --THE ONLY VARIABLE YOU MUST CONFIGURE IN THIS SCRIPT
- local ignores = {char,workspace.rayStorage}
- local speed = config:WaitForChild('bulletSpeed')
- local zoom = config:WaitForChild('zoom')
- local canScope = config:WaitForChild('canScope')
- local rayColor = config:WaitForChild('rayColor')
- local fireMode = config:WaitForChild('fireMode')
- local isLaser = config:WaitForChild('laserBullets')
- local ammo = config:WaitForChild('ammo')
- local tk = config:WaitForChild('tk')
- local exp = config:WaitForChild('explosion')
- local dmg = config:WaitForChild('damage')
- local fireSound = script.Parent.Handle.fire
- local reload = script.Parent.Handle.reload
- local hitmark = Instance.new('Sound')
- hitmark.SoundId = 'rbxassetid://160432334'
- hitmark.Volume = .5
- hitmark.Parent = plr.PlayerGui
- local firerate = config:WaitForChild('firerate')
- local reloadTime = config:WaitForChild('reloadTime')
- --animation stuff
- local holdAnim = humanoid:LoadAnimation(config:WaitForChild('holdGun'))
- local reloadAnim = humanoid:LoadAnimation(config:WaitForChild('reload'))
- local sprintAnim = humanoid:LoadAnimation(config:WaitForChild('sprint'))
- local crouchAnim = humanoid:LoadAnimation(config:WaitForChild('crouch'))
- local R15sprintAnim = humanoid:LoadAnimation(config:WaitForChild('r15sprint'))
- local R15holdAnim = humanoid:LoadAnimation(config:WaitForChild('r15holdGun'))
- local R15crouchAnim = humanoid:LoadAnimation(config:WaitForChild('r15crouch'))
- local R15reloadAnim = humanoid:LoadAnimation(config:WaitForChild('r15reload'))
- --priority declarations
- R15crouchAnim.Priority = Enum.AnimationPriority.Action
- R15holdAnim.Priority = Enum.AnimationPriority.Action
- R15reloadAnim.Priority = Enum.AnimationPriority.Action
- R15sprintAnim.Priority = Enum.AnimationPriority.Action
- --functions
- function flash(light)
- light.Enabled=true
- delay(.1,function()
- light.Enabled=false
- end)
- end
- function reflect(input,normal)
- return -2*input:Dot(normal)*normal+input
- end
- function updateGUI()
- if plr.PlayerGui:FindFirstChild('GunGUI') == nil then
- local guiClone = script.GunGUI:Clone()
- guiClone.Parent = plr.PlayerGui
- guiClone.Frame.ammo.Text = ammo.Value..'/'..ammo.MaxValue
- guiClone.Frame.name.Text = tool.Name
- if reloading then
- guiClone.Frame.reloading.TextColor3 = Color3.new(1, 0, 0.0156863)
- guiClone.Frame.reloading.Text = 'RELOADING'
- else
- guiClone.Frame.reloading.TextColor3 = Color3.new(0, 255, 0)
- guiClone.Frame.reloading.Text = 'READY'
- end
- if scoping then
- guiClone.Scope.Visible=true
- is.MouseIconEnabled=false
- camera.FieldOfView=zoom.Value
- elseif not scoping then
- guiClone.Scope.Visible=false
- is.MouseIconEnabled=true
- camera.FieldOfView=70
- end
- else
- local gui = plr.PlayerGui:FindFirstChild('GunGUI')
- gui.Enabled = true
- gui.Frame.ammo.Text = ammo.Value..'/'..ammo.MaxValue
- gui.Frame.name.Text = tool.Name
- if reloading then
- gui.Frame.reloading.TextColor3 = Color3.new(1, 0, 0.0156863)
- gui.Frame.reloading.Text = 'RELOADING'
- else
- gui.Frame.reloading.TextColor3 = Color3.new(0, 255, 0)
- gui.Frame.reloading.Text = 'READY'
- end
- if scoping then
- gui.Scope.Visible = true
- is.MouseIconEnabled = false
- camera.FieldOfView = zoom.Value
- elseif not scoping then
- gui.Scope.Visible = false
- is.MouseIconEnabled = true
- camera.FieldOfView=70
- end
- end
- end
- function fire(mP,bPos)
- for _,v in next,barrel:GetChildren() do
- if v:IsA('ParticleEmitter') then
- v.Enabled = true
- delay(.02,function()
- for _,v in next,barrel:GetChildren() do
- if v:IsA('ParticleEmitter') then
- v.Enabled = false
- end
- end
- end)
- end
- end
- local mPos = mP.p + Vector3.new(math.random(-spread,spread),math.random(-spread,spread),math.random(-spread,spread))
- local b
- if not isLaser.Value then
- b = game:GetService('ReplicatedStorage').realBullet:Clone()
- else
- b = game:GetService('ReplicatedStorage').bullet:Clone()
- b.ParticleEmitter.Color = ColorSequence.new(rayColor.Value)
- b.ParticleEmitter:Emit(50)
- end
- local start = CFrame.new(bPos,mPos)*CFrame.new(0,0,-2)
- b.CFrame = start
- b.Parent = workspace.rayStorage
- flash(barrel.flash)
- sound:FireServer(fireSound)
- render:FireServer(bPos,mPos,rayColor.Value,speed.Value,ignores,isLaser.Value)
- ammo.Value = ammo.Value-1
- updateGUI()
- local latency = 0
- local lastStep = bPos
- spawn(function()
- while (b.CFrame.p-start.p).magnitude < 999 do
- latency = run.RenderStepped:Wait()
- if not isLaser.Value then
- b.CFrame = b.CFrame*CFrame.new(0,0,-latency*speed.Value)*CFrame.Angles(math.rad(-.1),0,0)
- else
- b.CFrame = b.CFrame*CFrame.new(0,0,-latency*speed.Value)
- end
- local part,position,norm = workspace:FindPartOnRayWithIgnoreList(Ray.new(lastStep,(b.Position-lastStep).unit*(lastStep-b.Position).magnitude),ignores)
- if part then
- if part.Name:lower() == 'reflect' and isLaser.Value then
- spawn(function()
- local ref = reflect(position-bPos,norm)
- local _,refLook = workspace:FindPartOnRayWithIgnoreList(Ray.new(position,((position+ref)-position).unit*999),ignores)
- local b2 = game:GetService('ReplicatedStorage').bullet:Clone()
- local start2 = CFrame.new(position,refLook)
- b2.CFrame = start2
- b2.ParticleEmitter.Color = ColorSequence.new(rayColor.Value)
- b2.ParticleEmitter:Emit(50)
- b2.Parent = workspace.rayStorage
- render:FireServer(position,refLook,rayColor.Value,speed.Value,ignores,isLaser.Value)
- local latency2 = 0
- local lastStep2 = position
- while (b2.CFrame.p-start2.p).magnitude < 999 do
- latency2 = run.RenderStepped:Wait()
- b2.CFrame = b2.CFrame*CFrame.new(0,0,-latency2*speed.Value)
- local part2,position2,norm2 = workspace:FindPartOnRayWithIgnoreList(Ray.new(lastStep2,(b2.Position-lastStep).unit*(lastStep2-b2.Position).magnitude),ignores)
- if part2 then
- local h2 = game:GetService('ReplicatedStorage').hit:Clone()
- h2.Parent = workspace.rayStorage
- h2.CFrame = CFrame.new(position2,position2+norm2)
- game:GetService('Debris'):AddItem(h2,15)
- for _,v in next,h2:GetChildren()do
- if v:IsA('ParticleEmitter') or v:IsA('PointLight') then
- v.Enabled = true
- end
- end
- delay(.1,function()
- for _,v in next,h2:GetChildren()do
- if v:IsA('ParticleEmitter') or v:IsA('PointLight') then
- v.Enabled = false
- end
- end
- end)
- if exp.Value then
- explodeEvent:FireServer(position2)
- end
- if plrs:GetPlayerFromCharacter(part2.Parent) then
- damageEvent:FireServer(dmg.Value,part2.Parent.Humanoid)
- elseif plrs:GetPlayerFromCharacter(part2.Parent.Parent) then
- damageEvent:FireServer(dmg.Value,part2.Parent.Parent.Humanoid)
- end
- break
- end
- end
- b2:Destroy()
- end)
- end
- if not part.Parent:FindFirstChild('Humanoid') or part.Parent.Parent:FindFirstChild('Humanoid') then
- local h = game:GetService('ReplicatedStorage').hit:Clone()
- h.Parent = workspace.rayStorage
- h.CFrame = CFrame.new(position,position+norm)
- h.Sound:Play()
- game:GetService('Debris'):AddItem(h,15)
- for _,v in next,h:GetChildren()do
- if v:IsA('ParticleEmitter') or v:IsA('PointLight') then
- v.Enabled = true
- end
- end
- delay(.1,function()
- for _,v in next,h:GetChildren()do
- if v:IsA('ParticleEmitter') or v:IsA('PointLight') then
- v.Enabled = false
- end
- end
- end)
- else
- if not isLaser.Value then
- local h = game:GetService('ReplicatedStorage').blood:Clone()
- h.Parent = workspace.rayStorage
- h.CFrame = CFrame.new(position,position+norm)
- game:GetService('Debris'):AddItem(h,3)
- for _,v in next,h:GetChildren()do
- if v:IsA('ParticleEmitter') or v:IsA('PointLight') then
- v.Enabled = true
- end
- end
- delay(.1,function()
- for _,v in next,h:GetChildren()do
- if v:IsA('ParticleEmitter') or v:IsA('PointLight') then
- v.Enabled = false
- end
- end
- end)
- end
- end
- if exp.Value then
- explodeEvent:FireServer(position)
- end
- if part.Parent:FindFirstChild('Humanoid') then
- if tk.Value then
- damageEvent:FireServer(dmg.Value,part.Parent.Humanoid)
- hitmark:Play()
- elseif not tk.Value then
- if plrs:GetPlayerFromCharacter(part.Parent) then
- if plrs:GetPlayerFromCharacter(part.Parent).TeamColor ~= plr.TeamColor then
- damageEvent:FireServer(dmg.Value,part.Parent.Humanoid)
- hitmark:Play()
- end
- else
- damageEvent:FireServer(dmg.Value,part.Parent.Humanoid)
- hitmark:Play()
- end
- end
- elseif part.Parent.Parent:FindFirstChild('Humanoid') then
- if tk.Value then
- damageEvent:FireServer(dmg.Value,part.Parent.Parent.Humanoid)
- hitmark:Play()
- elseif not tk.Value then
- if plrs:GetPlayerFromCharacter(part.Parent.Parent) then
- if plrs:GetPlayerFromCharacter(part.Parent.Parent).TeamColor ~= plr.TeamColor then
- damageEvent:FireServer(dmg.Value,part.Parent.Parent.Humanoid)
- hitmark:Play()
- end
- else
- damageEvent:FireServer(dmg.Value,part.Parent.Parent.Humanoid)
- hitmark:Play()
- end
- end
- end
- break
- end
- lastStep = b.Position
- end
- b:Destroy()
- end)
- end
- --main framework
- script.Parent.Equipped:Connect(function()
- mouse.Icon = 'http://www.roblox.com/asset/?id=410597427'
- equipped = true
- if humanoid.RigType == Enum.HumanoidRigType.R6 then
- holdAnim:Play()
- else
- R15holdAnim:Play()
- end
- updateGUI()
- mouse.Button1Down:Connect(function()
- if equipped then
- mouseDown = true
- mouse.Button1Up:Connect(function() mouseDown = false end)
- if fireMode.Value == 'Semi' then
- if not reloading and ammo.Value > 0 and humanoid.Health>0 and equipped and canFire then
- if sprint then
- sprintAnim:Stop()
- sprint = false
- end
- canFire = false
- fire(mouse.Hit,barrel.Position)
- wait(firerate.Value)
- canFire = true
- end
- elseif fireMode.Value == 'Auto' then
- while canFire and not reloading and ammo.Value > 0 and humanoid.Health > 0 and equipped and canFire and mouseDown do
- if sprint then
- sprintAnim:Stop()
- sprint = false
- end
- canFire=false
- fire(mouse.Hit,barrel.CFrame.p)
- sound:FireServer(fireSound)
- wait(firerate.Value)
- canFire=true
- end
- end
- end
- end)
- mouse.Button2Down:Connect(function()
- if equipped then
- if canScope.Value then
- if (camera.Focus.p-camera.CoordinateFrame.p).magnitude<1 then
- scoping = true
- updateGUI()
- end
- end
- end
- end)
- mouse.Button2Up:Connect(function()
- if equipped then
- if canScope.Value then
- scoping = false
- updateGUI()
- end
- end
- end)
- end)
- script.Parent.Unequipped:Connect(function()
- mouse.Icon = ''
- equipped = false
- sprint = false
- if humanoid.RigType == Enum.HumanoidRigType.R6 then
- sprintAnim:Stop()
- crouchAnim:Stop()
- holdAnim:Stop()
- else
- R15sprintAnim:Stop()
- R15crouchAnim:Stop()
- R15holdAnim:Stop()
- end
- crouching = false
- if plr.PlayerGui:FindFirstChild('GunGUI') then
- plr.PlayerGui.GunGUI.Enabled=false
- end
- end)
- --KeyDown functions
- is.InputBegan:Connect(function(key,gpe)
- if not gpe and equipped then
- if key.KeyCode == Enum.KeyCode.R then
- if not sprint then
- reloading = true
- updateGUI()
- sound:FireServer(reload)
- if humanoid.RigType == Enum.HumanoidRigType.R6 then
- reloadAnim:Play()
- else
- R15reloadAnim:Play()
- end
- wait(reloadTime.Value)
- reloading = false
- ammo.Value=ammo.MaxValue
- updateGUI()
- end
- elseif key.KeyCode == Enum.KeyCode.C then
- if not crouching and not sitting then
- crouching = true
- if humanoid.RigType == Enum.HumanoidRigType.R6 then
- crouchAnim:Play()
- else
- R15crouchAnim:Play()
- end
- elseif crouching and not sitting then
- crouching = false
- if humanoid.RigType == Enum.HumanoidRigType.R6 then
- crouchAnim:Stop()
- else
- R15crouchAnim:Stop()
- end
- end
- elseif key.KeyCode == Enum.KeyCode.F then
- if not sprint and not crouching and not sprint then
- sprint = true
- if humanoid.RigType == Enum.HumanoidRigType.R6 then
- sprintAnim:Play()
- else
- R15sprintAnim:Play()
- end
- elseif sprint and not crouching then
- sprint = false
- if humanoid.RigType == Enum.HumanoidRigType.R6 then
- sprintAnim:Stop()
- else
- R15sprintAnim:Stop()
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement