Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tool = script.Parent
- local flashPart = tool:WaitForChild("FlashPart")
- local chamber = tool:WaitForChild("Chamber")
- local trigger = tool:WaitForChild("Trigger")
- local triggerPoint1 = tool:WaitForChild("TriggerNotPressed")
- local triggerPoint2 = tool:WaitForChild("TriggerPressed")
- local ammo = script:WaitForChild("Ammo")
- local equipSound = script:WaitForChild("Equip")
- local reloadSound = script:WaitForChild("Reload")
- local shootSound = script:WaitForChild("Shoot")
- local onBulletShot = script.Parent:WaitForChild("OnBulletShot")
- local onReload = script.Parent:WaitForChild("OnReload")
- local onCursorChange = script.Parent:WaitForChild("OnCursorChange")
- local isReloading = false
- local tweenService = game:GetService("TweenService")
- local idleAnim = tool:WaitForChild("Idle")
- local idleAnimTrack
- local shootAnim = tool:WaitForChild("Shoot")
- local reloadAnim = tool:WaitForChild("Reload")
- local function playSound(sound)
- sound:Play()
- end
- local function reload()
- if isReloading or ammo.Value == 10 then return end
- isReloading = true
- onCursorChange:FireClient(game.Players:GetPlayerFromCharacter(tool.Parent), game.ServerStorage.CrosshairReloading.Texture)
- playSound(reloadSound)
- local reloadAnimTrack = tool.Parent.Humanoid:LoadAnimation(reloadAnim)
- reloadAnimTrack:Play()
- chamber.Transparency = 1
- for i, childOfChamber in pairs(chamber:GetChildren()) do
- if childOfChamber:IsA("MeshPart") then childOfChamber.Transparency = 1 end
- end
- local chamberClone = game.ServerStorage.Chamber:Clone()
- chamberClone.WeldConstraint.Part0 = chamberClone
- chamberClone.WeldConstraint.Part1 = tool.Parent.LeftHand
- chamberClone.CFrame = tool.Parent.LeftHand.CFrame * CFrame.Angles(0, 90, 0) + Vector3.new(0, -0.196, 0)
- chamberClone.Parent = tool.Parent
- reloadAnimTrack.Stopped:Wait()
- chamberClone:Destroy()
- chamber.Transparency = 0
- for i, childOfChamber in pairs(chamber:GetChildren()) do
- if childOfChamber:IsA("MeshPart") then childOfChamber.Transparency = 0 end
- end
- reloadSound.Ended:Wait()
- ammo.Value = 10
- isReloading = false
- if game.Players:GetPlayerFromCharacter(tool.Parent) then onCursorChange:FireClient(game.Players:GetPlayerFromCharacter(tool.Parent), game.ServerStorage.Crosshair.Texture) end
- end
- local function shootFunc(plr, hit, target)
- if isReloading then return end
- if ammo.Value < 1 then
- reload()
- return
- end
- local ray = Ray.new(flashPart.Position, (hit.Position - flashPart.Position).unit * 100)
- local part, pos, globalVec = workspace:FindPartOnRay(ray, tool.Parent, false, true)
- if part then
- if part.Parent:FindFirstChild("Humanoid") then part.Parent.Humanoid:TakeDamage(30) end
- end
- local bulletRay = Instance.new("Part")
- bulletRay.CanCollide = false
- bulletRay.Anchored = true
- local size = (hit.Position - flashPart.Position).Magnitude
- if size > 2048 then size = 2048 end
- bulletRay.CFrame = CFrame.new(flashPart.Position, pos) * CFrame.new(0, 0, -size / 2)
- bulletRay.Size = Vector3.new(0.1, 0.1, size)
- bulletRay.Color = Color3.fromRGB(255, 223, 0)
- bulletRay.Parent = workspace
- local bulletHole = game.ServerStorage.BulletHole:Clone()
- bulletHole.CFrame = CFrame.new(hit.Position, hit.Position + globalVec)
- bulletHole.Parent = workspace
- game:GetService("Debris"):AddItem(bulletRay, 0.2)
- game:GetService("Debris"):AddItem(bulletHole, 5)
- playSound(shootSound)
- ammo.Value = ammo.Value - 1
- tool.Parent.Humanoid:LoadAnimation(shootAnim):Play()
- for i, flashEffect in pairs(flashPart:GetChildren()) do
- if flashEffect.Name == "FlashGui" then flashEffect.Enabled = true end
- if flashEffect.Name == "Light" then flashEffect.Enabled = true end
- end
- wait(0.06)
- for i, flashEffect in pairs(flashPart:GetChildren()) do
- if flashEffect.Name == "FlashGui" then flashEffect.Enabled = false end
- if flashEffect.Name == "Light" then flashEffect.Enabled = false end
- end
- end
- tool.Equipped:Connect(function()
- onCursorChange:FireClient(game.Players:GetPlayerFromCharacter(tool.Parent), game.ServerStorage.Crosshair.Texture)
- local ammoGui = script.AmmoGui:Clone()
- ammoGui.AmmoStatus.Text = ammo.Value .. "/10"
- ammoGui.Parent = game.Players:GetPlayerFromCharacter(tool.Parent).PlayerGui
- playSound(equipSound)
- if not idleAnimTrack then idleAnimTrack = tool.Parent.Humanoid:LoadAnimation(idleAnim) end
- if not idleAnimTrack.IsPlaying then idleAnimTrack:Play() end
- end)
- tool.Unequipped:Connect(function()
- onCursorChange:FireClient(tool.Parent.Parent, "")
- if tool.Parent.Parent.PlayerGui:FindFirstChild("AmmoGui") then tool.Parent.Parent.PlayerGui.AmmoGui:Destroy() end
- playSound(equipSound)
- if idleAnimTrack and idleAnimTrack.IsPlaying then idleAnimTrack:Stop() end
- end)
- onBulletShot.OnServerEvent:Connect(shootFunc)
- onReload.OnServerEvent:Connect(reload)
- ammo:GetPropertyChangedSignal("Value"):Connect(function()
- if game.Players:GetPlayerFromCharacter(tool.Parent) then game.Players:GetPlayerFromCharacter(tool.Parent).PlayerGui.AmmoGui.AmmoStatus.Text = ammo.Value .. "/10" end
- end)
Add Comment
Please, Sign In to add comment