Tool=script.Parent Handle=Tool:WaitForChild("\072\097\110\100\108\101")Players=game:GetService("\080\108\097\121\101\114\115")Debris=game:GetService("\068\101\098\114\105\115")RunService=game:GetService("\082\117\110\083\101\114\118\105\099\101")UserInputService=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")AmmoDisplay=(script:WaitForChild("\065\109\109\111\068\105\115\112\108\097\121")):Clone()CastLaser=(Tool:WaitForChild("\067\097\115\116\076\097\115\101\114")):Clone()Camera=(game:GetService("\087\111\114\107\115\112\097\099\101")).CurrentCamera BaseUrl="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061"AnimationTracks={}LocalObjects={}Animations={Hold={Animation=Tool:WaitForChild("\072\111\108\100"),FadeTime=nil,Weight=nil,Speed=1;Duration=2};Fire={Animation=Tool:WaitForChild("\070\105\114\101"),FadeTime=.25;Weight=nil;Speed=.5,Duration=.5},Reload={Animation=Tool:WaitForChild("\082\101\108\111\097\100");FadeTime=nil;Weight=nil,Speed=1;Duration=2}}Sounds={Reload=Handle:WaitForChild("\082\101\108\111\097\100");NoAmmo=Handle:WaitForChild("\078\111\065\109\109\111")}Modules=Tool:WaitForChild("\077\111\100\117\108\101\115")Functions=require(Modules:WaitForChild("\070\117\110\099\116\105\111\110\115"))Remotes=Tool:WaitForChild("\082\101\109\111\116\101\115")ServerControl=Remotes:WaitForChild("\083\101\114\118\101\114\067\111\110\116\114\111\108")ClientControl=Remotes:WaitForChild("\067\108\105\101\110\116\067\111\110\116\114\111\108")ConfigurationBin=Tool:WaitForChild("\067\111\110\102\105\103\117\114\097\116\105\111\110")Configuration={}Configuration=Functions.CreateConfiguration(ConfigurationBin,Configuration)InputCheck=Instance.new("\083\099\114\101\101\110\071\117\105")InputCheck.Name="\073\110\112\117\116\067\104\101\099\107"InputButton=Instance.new("\073\109\097\103\101\066\117\116\116\111\110")InputButton.Name="\073\110\112\117\116\066\117\116\116\111\110"InputButton.Image=""InputButton.BackgroundTransparency=1 InputButton.ImageTransparency=1 InputButton.Size=UDim2.new(1,0,1,0)InputButton.Parent=InputCheck Cursors={Normal=BaseUrl.."\049\055\048\057\048\056\054\054\053";EnemyHit=BaseUrl.."\049\055\050\054\049\056\050\053\057"}Rate=.016666666666667 FiringOffset=Vector3.new(0,Handle.Size.Y/4-.2,-(Handle.Size.Z/2))Reloading=false MouseDown=false ToolEquipped=false Tool.Enabled=true function SetAnimation(O,K)if O=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(K and(ToolEquipped and Humanoid))then for O,a in pairs(AnimationTracks)do if a.Animation==K.Animation then a.AnimationTrack:Stop()table.remove(AnimationTracks,O)end end local O=Humanoid:LoadAnimation(K.Animation)table.insert(AnimationTracks,{Animation=K.Animation;AnimationTrack=O})O:Play(K.FadeTime,K.Weight,K.Speed)elseif O=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and K then for O,a in pairs(AnimationTracks)do if a.Animation==K.Animation then a.AnimationTrack:Stop(K.FadeTime)table.remove(AnimationTracks,O)end end end end function ToggleGui()if not AmmoDisplayClone or not AmmoDisplayClone.Parent then return end local O=AmmoDisplayClone.Frame local K=O.Ammo if Configuration.Ammo.ClipSize.MaxValue>0 then K.AmmoCounter.CounterPart.Text=Configuration.Ammo.ClipSize.Value end K.MagCounter.CounterPart.Text=Configuration.Ammo.Magazines.Value end function Reload()if Reloading or not Tool.Enabled or Configuration.Ammo.Magazines.Value>=Configuration.Ammo.Magazines.MaxValue then return end Tool.Enabled=false Reloading=true ToggleGui()local O=true if Configuration.Ammo.ClipSize.MaxValue>0 and Configuration.Ammo.ClipSize.Value<=0 then O=false else O=true end if O then Spawn(function()local O=Animations.Reload OnClientInvoke("\080\108\097\121\065\110\105\109\097\116\105\111\110",O)wait(O.Duration)OnClientInvoke("\083\116\111\112\065\110\105\109\097\116\105\111\110",O)end)Sounds.Reload:Play()local O=Configuration.Ammo.Magazines.MaxValue>0 and Configuration.Ammo.Magazines.MaxValue-Configuration.Ammo.Magazines.Value or Configuration.Ammo.ClipSize.MaxValue if Configuration.Ammo.ClipSize.MaxValue>0 then O=O>Configuration.Ammo.ClipSize.Value and Configuration.Ammo.ClipSize.Value or O end wait(Configuration.ReloadTime.Value)Configuration.Ammo.Magazines.Value=Configuration.Ammo.Magazines.Value+O Configuration.Ammo.ClipSize.Value=Configuration.Ammo.ClipSize.Value-O Sounds.Reload:Stop()ToggleGui()end Reloading=false Tool.Enabled=true end function RayTouched(O,K)if not O or not O.Parent then return end local a=O.Parent if a:IsA("\072\097\116")then a=a.Parent end if a==Character then return end local R=a:FindFirstChild("\072\117\109\097\110\111\105\100")local b=Sounds.RayHit if not R or R.Health==0 then return end local v=Players:GetPlayerFromCharacter(a)if v and Functions.IsTeamMate(Player,v)then return end Spawn(function()IconChangeTick=tick()PlayerMouse.Icon=Cursors.EnemyHit wait(1)if tick()-IconChangeTick>=.95 and(ToolEquipped and PlayerMouse)then PlayerMouse.Icon=Cursors.Normal end end)end function FireRay(O,K)local a=(CFrame.new(O,K)).lookVector local R,b,v=Functions.CastRay(O,a,Configuration.Range.Value,{Character},false)local l=Player:FindFirstChild("\066\097\099\107\112\097\099\107")if l then local K=CastLaser:Clone()local a=Instance.new("\086\101\099\116\111\114\051\086\097\108\117\101")a.Name="\083\116\097\114\116\080\111\115\105\116\105\111\110"a.Value=O a.Parent=K local R=Instance.new("\086\101\099\116\111\114\051\086\097\108\117\101")R.Name="\084\097\114\103\101\116\080\111\115\105\116\105\111\110"R.Value=b R.Parent=K local v=Instance.new("\066\111\111\108\086\097\108\117\101")v.Name="\082\097\121\072\105\116"v.Value=v v.Parent=K K.Disabled=false K.Parent=l end Spawn(function()InvokeServer("\067\097\115\116\076\097\115\101\114",{StartPosition=O;TargetPosition=b;RayHit=R and true or false})end)Spawn(function()InvokeServer("\082\097\121\072\105\116",{Hit=R;Position=b})end)RayTouched(R,b)end function Button1Pressed(O)if not O and MouseDown then MouseDown=false end end function KeyPress(O,K)if O=="\114"and K then Reload()end end function Activated()if not Tool.Enabled or not ToolEquipped or Reloading then return end Tool.Enabled=false if Configuration.Ammo.Magazines.Value>0 then local O=false if Configuration.Automatic.Value then MouseDown=true end OnClientInvoke("\083\116\111\112\065\110\105\109\097\116\105\111\110",{Animation=Animations.Fire.Animation,FadeTime=nil})OnClientInvoke("\080\108\097\121\065\110\105\109\097\116\105\111\110",Animations.Fire)while MouseDown or not O and(ToolEquipped and CheckIfAlive())do if Configuration.Ammo.Magazines.Value<=0 or not ToolEquipped or not CheckIfAlive()then break end if not O then O=true end local K=math.random(Configuration.Burst.Bullets.MinValue,Configuration.Burst.Bullets.MaxValue)local a=false Spawn(function()InvokeServer("\070\105\114\101",true)end)for O=1,K>0 and K or 1,1 do local a=OnClientInvoke("\077\111\117\115\101\080\111\115\105\116\105\111\110")if not a then break end a=a.Position local R=(Handle.CFrame*CFrame.new(FiringOffset.X,FiringOffset.Y,FiringOffset.Z)).p if K>0 then local O=Configuration.Burst.Offset.Value*100 a=a+Vector3.new(math.random(-O.X,O.X)*.01,math.random(-O.Y,O.Y)*.01,math.random(-O.Z,O.Z)*.01)end local b=Configuration.Accuracy.Value*100 a=a+Vector3.new(math.random(-b.X,b.X)*.01,math.random(-b.Y,b.Y)*.01,math.random(-b.Z,b.Z)*.01)Configuration.Ammo.Magazines.Value=Configuration.Ammo.Magazines.Value-1 FireRay(R,a)end ToggleGui()wait(Configuration.FireRate.Value)end OnClientInvoke("\083\116\111\112\065\110\105\109\097\116\105\111\110",{Animation=Animations.Fire.Animation,FadeTime=.25})else Tool.Enabled=true Sounds.NoAmmo:Play()Reload()end MouseDown=false Tool.Enabled=true if Configuration.Ammo.Magazines.Value<=0 then Sounds.NoAmmo:Play()Reload()end end function CheckIfAlive()return(Player and(Player.Parent and(Character and(Character.Parent and(Humanoid and(Humanoid.Parent and Humanoid.Health>0))))))and true or false end function Equipped(O)Character=Tool.Parent Player=Players:GetPlayerFromCharacter(Character)Humanoid=Character:FindFirstChild("\072\117\109\097\110\111\105\100")if not CheckIfAlive()then return end ToolEquipped=true Spawn(function()PlayerMouse=Player:GetMouse()O.Button1Down:connect(function()Button1Pressed(true)end)O.Button1Up:connect(function()Button1Pressed(false)end)O.KeyDown:connect(function(O)KeyPress(O,true)end)O.KeyUp:connect(function(O)KeyPress(O,false)end)Humanoid.CameraOffset=Vector3.new(0,.35,0)OnClientInvoke("\080\108\097\121\065\110\105\109\097\116\105\111\110",Animations.Hold)local K=Player:FindFirstChild("\080\108\097\121\101\114\071\117\105")if K then if UserInputService.TouchEnabled then InputCheckClone=InputCheck:Clone()InputCheckClone.InputButton.InputBegan:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=true})end)InputCheckClone.InputButton.InputEnded:connect(function()InvokeServer("\066\117\116\116\111\110\049\067\108\105\099\107",{Down=false})end)InputCheckClone.Parent=K end local function O()local O=AmmoDisplayClone.Frame O.CurrentWeapon.Text=Configuration.ToolName.Value local K=O.Ammo K.AmmoCounter.CounterPart.Text=Configuration.Ammo.ClipSize.MaxValue>0 and Configuration.Ammo.ClipSize.Value or"--"K.MagCounter.CounterPart.Text=Configuration.Ammo.Magazines.Value end AmmoDisplayClone=AmmoDisplay:Clone()O()AmmoDisplayClone.Parent=K ToggleGui()for O,K in pairs({ClipSizeChanged;MagazinesChanged})do if K then K:disconnect()end end ClipSizeChanged=Configuration.Ammo.ClipSize.Changed:connect(function()O()end)MagazinesChanged=Configuration.Ammo.Magazines.Changed:connect(function()O()end)end for O,K in pairs({"\076\101\102\116 \065\114\109";"\082\105\103\104\116 \065\114\109"})do local a=Character:FindFirstChild(K)if a then Spawn(function()OnClientInvoke("\083\101\116\076\111\099\097\108\084\114\097\110\115\112\097\114\101\110\099\121\077\111\100\105\102\105\101\114",{Object=a;Transparency=0;AutoUpdate=false})end)end end O.Icon=Cursors.Normal end)end function Unequipped()LocalObjects={}if CheckIfAlive()then Humanoid.CameraOffset=Vector3.new(0,0,0)end for O,K in pairs(Sounds)do K:Stop()end if PlayerMouse then PlayerMouse.Icon=""end for O,K in pairs({InputCheckClone;ObjectLocalTransparencyModifier,AmmoDisplayClone;ClipSizeChanged;MagazinesChanged})do if tostring(K)=="\067\111\110\110\101\099\116\105\111\110"then K:disconnect()elseif K and K.Parent then K:Destroy()end end MouseDown=false for O,K in pairs(AnimationTracks)do if K and K.AnimationTrack then K.AnimationTrack:Stop()end end AnimationTracks={}ToolEquipped=false end function InvokeServer(O,K)pcall(function()local a=ServerControl:InvokeServer(O,K)return a end)end function OnClientInvoke(O,K)if O=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(K and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",K)elseif O=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and K then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",K)elseif O=="\080\108\097\121\083\111\117\110\100"and K then K:Play()elseif O=="\083\116\111\112\083\111\117\110\100"and K then K:Stop()elseif O=="\077\111\117\115\101\080\111\115\105\116\105\111\110"then return{Position=PlayerMouse.Hit.p;Target=PlayerMouse.Target}elseif O=="\083\101\116\076\111\099\097\108\084\114\097\110\115\112\097\114\101\110\099\121\077\111\100\105\102\105\101\114"and(K and ToolEquipped)then pcall(function()local O=false for a,R in pairs(LocalObjects)do if R==K then O=true end end if not O then table.insert(LocalObjects,K)if ObjectLocalTransparencyModifier then ObjectLocalTransparencyModifier:disconnect()end ObjectLocalTransparencyModifier=RunService.RenderStepped:connect(function()for O,K in pairs(LocalObjects)do if K.Object and K.Object.Parent then local O=K.Object.LocalTransparencyModifier if not K.AutoUpdate and(O==1 or O==0)or K.AutoUpdate then K.Object.LocalTransparencyModifier=K.Transparency end else table.remove(LocalObjects,O)end end end)end end)end end ClientControl.OnClientInvoke=OnClientInvoke Tool.Activated:connect(Activated)Tool.Equipped:connect(Equipped)Tool.Unequipped:connect(Unequipped)


Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")
Debris = game:GetService("Debris")
RunService = game:GetService("RunService")
UserInputService = game:GetService("UserInputService")

AmmoDisplay = script:WaitForChild("AmmoDisplay"):Clone()
CastLaser = Tool:WaitForChild("CastLaser"):Clone()

Camera = game:GetService("Workspace").CurrentCamera

BaseUrl = "http://www.roblox.com/asset/?id="

AnimationTracks = {}
LocalObjects = {}

Animations = {
	Hold = {Animation = Tool:WaitForChild("Hold"), FadeTime = nil, Weight = nil, Speed = 1, Duration = 2},
	Fire = {Animation = Tool:WaitForChild("Fire"), FadeTime = 0.25, Weight = nil, Speed = 0.5, Duration = 0.5},
	Reload = {Animation = Tool:WaitForChild("Reload"), FadeTime = nil, Weight = nil, Speed = 1, Duration = 2},
}

Sounds = {
	Reload = Handle:WaitForChild("Reload"),
	NoAmmo = Handle:WaitForChild("NoAmmo"),
}

Modules = Tool:WaitForChild("Modules")
Functions = require(Modules:WaitForChild("Functions"))

Remotes = Tool:WaitForChild("Remotes")
ServerControl = Remotes:WaitForChild("ServerControl")
ClientControl = Remotes:WaitForChild("ClientControl")

ConfigurationBin = Tool:WaitForChild("Configuration")
Configuration = {}
Configuration = Functions.CreateConfiguration(ConfigurationBin, Configuration)

InputCheck = Instance.new("ScreenGui")
InputCheck.Name = "InputCheck"
InputButton = Instance.new("ImageButton")
InputButton.Name = "InputButton"
InputButton.Image = ""
InputButton.BackgroundTransparency = 1
InputButton.ImageTransparency = 1
InputButton.Size = UDim2.new(1, 0, 1, 0)
InputButton.Parent = InputCheck

Cursors = {
	Normal = (BaseUrl .. "170908665"),
	EnemyHit = (BaseUrl .. "172618259"),
}

Rate = (1 / 60)

FiringOffset = Vector3.new(0, ((Handle.Size.Y / 4) - 0.2), -(Handle.Size.Z / 2))

Reloading = false
MouseDown = false
ToolEquipped = false

Tool.Enabled = true

function SetAnimation(mode, value)
	if mode == "PlayAnimation" and value and ToolEquipped and Humanoid then
		for i, v in pairs(AnimationTracks) do
			if v.Animation == value.Animation then
				v.AnimationTrack:Stop()
				table.remove(AnimationTracks, i)
			end
		end
		local AnimationTrack = Humanoid:LoadAnimation(value.Animation)
		table.insert(AnimationTracks, {Animation = value.Animation, AnimationTrack = AnimationTrack})
		AnimationTrack:Play(value.FadeTime, value.Weight, value.Speed)
	elseif mode == "StopAnimation" and value then
		for i, v in pairs(AnimationTracks) do
			if v.Animation == value.Animation then
				v.AnimationTrack:Stop(value.FadeTime)
				table.remove(AnimationTracks, i)
			end
		end
	end
end

function ToggleGui()
	if not AmmoDisplayClone or not AmmoDisplayClone.Parent then
		return
	end
	local Frame = AmmoDisplayClone.Frame
	local Ammo = Frame.Ammo
	if Configuration.Ammo.ClipSize.MaxValue > 0 then
		Ammo.AmmoCounter.CounterPart.Text = Configuration.Ammo.ClipSize.Value
	end
	Ammo.MagCounter.CounterPart.Text = Configuration.Ammo.Magazines.Value
end

function Reload()
	if Reloading or not Tool.Enabled or Configuration.Ammo.Magazines.Value >= Configuration.Ammo.Magazines.MaxValue then
		return
	end
	Tool.Enabled = false
	Reloading = true
	ToggleGui()
	local CanReload = true
	if Configuration.Ammo.ClipSize.MaxValue > 0 and Configuration.Ammo.ClipSize.Value <= 0 then
		CanReload = false
	else
		CanReload = true
	end
	if CanReload then
		Spawn(function()
			local Animation = Animations.Reload
			OnClientInvoke("PlayAnimation", Animation)
			wait(Animation.Duration)
			OnClientInvoke("StopAnimation", Animation)
		end)
		Sounds.Reload:Play()
		local AddedClips = ((Configuration.Ammo.Magazines.MaxValue > 0 and (Configuration.Ammo.Magazines.MaxValue - Configuration.Ammo.Magazines.Value)) or Configuration.Ammo.ClipSize.MaxValue)
		if Configuration.Ammo.ClipSize.MaxValue > 0 then
			AddedClips = ((AddedClips > Configuration.Ammo.ClipSize.Value and Configuration.Ammo.ClipSize.Value) or AddedClips)
		end
		--[[local ReloadRate = (Configuration.ReloadTime.Value / Configuration.Ammo.Magazines.MaxValue)
		for i = 1, AddedClips do
			wait(ReloadTime)
			Configuration.Ammo.Magazines.Value = (Configuration.Ammo.Magazines.Value + 1)
		end]]
		wait(Configuration.ReloadTime.Value)
		Configuration.Ammo.Magazines.Value = (Configuration.Ammo.Magazines.Value + AddedClips)
		Configuration.Ammo.ClipSize.Value = (Configuration.Ammo.ClipSize.Value - AddedClips)
		Sounds.Reload:Stop()
		ToggleGui()
	end
	Reloading = false
	Tool.Enabled = true
end

function RayTouched(Hit, Position)
	if not Hit or not Hit.Parent then
		return
	end
	local character = Hit.Parent
	if character:IsA("Hat") then
		character = character.Parent
	end
	if character == Character then
		return
	end
	local humanoid = character:FindFirstChild("Humanoid")
	local SoundChosen = Sounds.RayHit
	if not humanoid or humanoid.Health == 0 then
		return
	end
	local player = Players:GetPlayerFromCharacter(character)
	if player and Functions.IsTeamMate(Player, player) then
		return
	end
	Spawn(function()
		IconChangeTick = tick()
		PlayerMouse.Icon = Cursors.EnemyHit
		wait(1)
		if (tick() - IconChangeTick) >= 0.95 and ToolEquipped and PlayerMouse then
			PlayerMouse.Icon = Cursors.Normal
		end
	end)
end

function FireRay(StartPosition, TargetPosition)
	local Direction = CFrame.new(StartPosition, TargetPosition).lookVector
	local RayHit, RayPos, RayNormal = Functions.CastRay(StartPosition, Direction, Configuration.Range.Value, {Character}, false)
	local Backpack = Player:FindFirstChild("Backpack")
	if Backpack then
		local LaserScript = CastLaser:Clone()
		local StartPos = Instance.new("Vector3Value")
		StartPos.Name = "StartPosition"
		StartPos.Value = StartPosition
		StartPos.Parent = LaserScript
		local TargetPos = Instance.new("Vector3Value")
		TargetPos.Name = "TargetPosition"
		TargetPos.Value = RayPos
		TargetPos.Parent = LaserScript
		local RayHit = Instance.new("BoolValue")
		RayHit.Name = "RayHit"
		RayHit.Value = RayHit
		RayHit.Parent = LaserScript
		LaserScript.Disabled = false
		LaserScript.Parent = Backpack
	end
	Spawn(function()
		InvokeServer("CastLaser", {StartPosition = StartPosition, TargetPosition = RayPos, RayHit = ((RayHit and true) or false)})
	end)
	Spawn(function()
		InvokeServer("RayHit", {Hit = RayHit, Position = RayPos})
	end)
	RayTouched(RayHit, RayPos)
end

function Button1Pressed(Down)
	if not Down and MouseDown then
		MouseDown = false
	end
end

function KeyPress(Key, Down)
	if Key == "r" and Down then
		Reload()
	end
end

function Activated()
	if not Tool.Enabled or not ToolEquipped or Reloading then
		return
	end
	Tool.Enabled = false
	if Configuration.Ammo.Magazines.Value > 0 then
		local FirstShot = false
		if Configuration.Automatic.Value then
			MouseDown = true
		end
		OnClientInvoke("StopAnimation", {Animation = Animations.Fire.Animation, FadeTime = nil})
		OnClientInvoke("PlayAnimation", Animations.Fire)
		while MouseDown or not FirstShot and ToolEquipped and CheckIfAlive() do
			if Configuration.Ammo.Magazines.Value <= 0 or not ToolEquipped or not CheckIfAlive() then
				break
			end
			if not FirstShot then
				FirstShot = true
			end
			local BurstAmount = math.random(Configuration.Burst.Bullets.MinValue, Configuration.Burst.Bullets.MaxValue)
			local WithinFiringRange = false
			Spawn(function()
				InvokeServer("Fire", true)
			end)
			for i = 1, ((BurstAmount > 0 and BurstAmount) or 1) do
				local TargetPosition = OnClientInvoke("MousePosition")
				if not TargetPosition then
					break
				end
				TargetPosition = TargetPosition.Position
				local StartPosition = (Handle.CFrame * CFrame.new(FiringOffset.X, FiringOffset.Y, FiringOffset.Z)).p
				if BurstAmount > 0 then
					local Offset = (Configuration.Burst.Offset.Value * 100)
					TargetPosition = TargetPosition + Vector3.new((math.random(-Offset.X, Offset.X) * 0.01), (math.random(-Offset.Y, Offset.Y) * 0.01), (math.random(-Offset.Z, Offset.Z) * 0.01))
				end
				local Accuracy = (Configuration.Accuracy.Value * 100)
				TargetPosition = TargetPosition + Vector3.new((math.random(-Accuracy.X, Accuracy.X) * 0.01), (math.random(-Accuracy.Y, Accuracy.Y) * 0.01), (math.random(-Accuracy.Z, Accuracy.Z) * 0.01))
				Configuration.Ammo.Magazines.Value = (Configuration.Ammo.Magazines.Value - 1)
				FireRay(StartPosition, TargetPosition)
			end
			ToggleGui()
			wait(Configuration.FireRate.Value)
		end
		OnClientInvoke("StopAnimation", {Animation = Animations.Fire.Animation, FadeTime = 0.25})
	else
		Tool.Enabled = true
		Sounds.NoAmmo:Play()
		Reload()
	end
	MouseDown = false
	Tool.Enabled = true
	if Configuration.Ammo.Magazines.Value <= 0 then
		Sounds.NoAmmo:Play()
		Reload()
	end
end

function CheckIfAlive()
	return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0) and true) or false)
end

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	if not CheckIfAlive() then
		return
	end
	ToolEquipped = true
	Spawn(function()
		PlayerMouse = Player:GetMouse()
		Mouse.Button1Down:connect(function()
			Button1Pressed(true)
		end)
		Mouse.Button1Up:connect(function()
			Button1Pressed(false)
		end)
		Mouse.KeyDown:connect(function(Key)
			KeyPress(Key, true)
		end)
		Mouse.KeyUp:connect(function(Key)
			KeyPress(Key, false)
		end)
		Humanoid.CameraOffset = Vector3.new(0, 0.35, 0)
		OnClientInvoke("PlayAnimation", Animations.Hold)
		local PlayerGui = Player:FindFirstChild("PlayerGui")
		if PlayerGui then
			if UserInputService.TouchEnabled then
				InputCheckClone = InputCheck:Clone()
				InputCheckClone.InputButton.InputBegan:connect(function()
					InvokeServer("Button1Click", {Down = true})
				end)
				InputCheckClone.InputButton.InputEnded:connect(function()
					InvokeServer("Button1Click", {Down = false})
				end)
				InputCheckClone.Parent = PlayerGui
			end
			local function AdjustAmmoDisplay()
				local Frame = AmmoDisplayClone.Frame
				Frame.CurrentWeapon.Text = Configuration.ToolName.Value
				local Ammo = Frame.Ammo
				Ammo.AmmoCounter.CounterPart.Text = ((Configuration.Ammo.ClipSize.MaxValue > 0 and Configuration.Ammo.ClipSize.Value) or "--")
				Ammo.MagCounter.CounterPart.Text = Configuration.Ammo.Magazines.Value
			end
			AmmoDisplayClone = AmmoDisplay:Clone()
			AdjustAmmoDisplay()
			AmmoDisplayClone.Parent = PlayerGui
			ToggleGui()
			for i, v in pairs({ClipSizeChanged, MagazinesChanged}) do
				if v then
					v:disconnect()
				end
			end
			ClipSizeChanged = Configuration.Ammo.ClipSize.Changed:connect(function()
				AdjustAmmoDisplay()
			end)
			MagazinesChanged = Configuration.Ammo.Magazines.Changed:connect(function()
				AdjustAmmoDisplay()
			end)
		end
		for i, v in pairs({"Left Arm", "Right Arm"}) do
			local Arm = Character:FindFirstChild(v)
			if Arm then
				Spawn(function()
					OnClientInvoke("SetLocalTransparencyModifier", {Object = Arm, Transparency = 0, AutoUpdate = false})
				end)
			end
		end
		Mouse.Icon = Cursors.Normal
	end)
end

function Unequipped()
	LocalObjects = {}
	if CheckIfAlive() then
		Humanoid.CameraOffset = Vector3.new(0, 0, 0)
	end
	for i, v in pairs(Sounds) do
		v:Stop()
	end
	if PlayerMouse then
		PlayerMouse.Icon = ""
	end
	for i, v in pairs({InputCheckClone, ObjectLocalTransparencyModifier, AmmoDisplayClone, ClipSizeChanged, MagazinesChanged}) do
		if tostring(v) == "Connection" then
			v:disconnect()
		elseif v and v.Parent then
			v:Destroy()
		end
	end
	MouseDown = false
	for i, v in pairs(AnimationTracks) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	AnimationTracks = {}
	ToolEquipped = false
end

function InvokeServer(mode, value)
	pcall(function()
		local ServerReturn = ServerControl:InvokeServer(mode, value)
		return ServerReturn
	end)
end

function OnClientInvoke(mode, value)
	if mode == "PlayAnimation" and value and ToolEquipped and Humanoid then
		SetAnimation("PlayAnimation", value)
	elseif mode == "StopAnimation" and value then
		SetAnimation("StopAnimation", value)
	elseif mode == "PlaySound" and value then
		value:Play()
	elseif mode == "StopSound" and value then
		value:Stop()
	elseif mode == "MousePosition" then
		return {Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target}
	elseif mode == "SetLocalTransparencyModifier" and value and ToolEquipped then
		pcall(function()
			local ObjectFound = false
			for i, v in pairs(LocalObjects) do
				if v == value then
					ObjectFound = true
				end
			end
			if not ObjectFound then
				table.insert(LocalObjects, value)
				if ObjectLocalTransparencyModifier then
					ObjectLocalTransparencyModifier:disconnect()
				end
				ObjectLocalTransparencyModifier = RunService.RenderStepped:connect(function()
					for i, v in pairs(LocalObjects) do
						if v.Object and v.Object.Parent then
							local CurrentTransparency = v.Object.LocalTransparencyModifier
							if ((not v.AutoUpdate and (CurrentTransparency == 1 or  CurrentTransparency == 0)) or v.AutoUpdate) then
								v.Object.LocalTransparencyModifier = v.Transparency
							end
						else
							table.remove(LocalObjects, i)
						end
					end
				end)
			end
		end)
	end
end

ClientControl.OnClientInvoke = OnClientInvoke

Tool.Activated:connect(Activated)
Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)
