local L=script.Parent.Parent.Parent local c=game.Players.LocalPlayer local X={KeyDown={{Key="\103",Description="\084\111\103\103\108\101 \076\097\115\101\114";Plugin=function()local X=L:WaitForChild("\076\097\115\101\114\076\105\103\104\116")local n=L:WaitForChild("\071\114\105\112")local G=L.Program_Client:WaitForChild("\105\103\110\111\114\101\067\111\100\101")local R=game.Workspace:WaitForChild("\066\117\108\108\101\116\077\111\100\101\108\058 "..c.Name)local e={}local m=(game.Players:GetPlayerFromCharacter(L.Parent)).Name local l=R local b=game:GetService("\082\117\110\083\101\114\118\105\099\101")local function t()local L=Instance.new("\080\097\114\116")L.Transparency=1 L.Name="\108\097\115\101\114\068\111\116"L.Anchored=true L.CanCollide=false L.FormFactor=Enum.FormFactor.Custom L.Size=Vector3.new(.25,.25,1)local c=Instance.new("\083\117\114\102\097\099\101\071\117\105")c.CanvasSize=Vector2.new(100,100)c.Parent=L local X=Instance.new("\073\109\097\103\101\076\097\098\101\108")X.BackgroundTransparency=1 X.Size=UDim2.new(1,0,1,0)X.Image="\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\049\051\049\051\057\052\055\051\057"X.Parent=c return L end local function D(L,c)local X={{"\066\097\099\107";c.CFrame*CFrame.new(0,0,c.Size.z)},{"\066\111\116\116\111\109",c.CFrame*CFrame.new(0,-c.Size.y,0)};{"\070\114\111\110\116";c.CFrame*CFrame.new(0,0,-c.Size.z)};{"\076\101\102\116";c.CFrame*CFrame.new(-c.Size.x,0,0)};{"\082\105\103\104\116",c.CFrame*CFrame.new(c.Size.x,0,0)},{"\084\111\112";c.CFrame*CFrame.new(0,c.Size.y,0)}}local n=math.huge local G=nil for c,X in pairs(X)do local R=(L-X[2].p).magnitude if R<n then n=R G=X end end local R=CFrame.new(c.CFrame.p,G[2].p)local e=R.lookVector*((c.CFrame.p-G[2].p).magnitude/2-.25)local m=(L-G[2].p)+e local l=(R+e)+m return l end local H=t()X.Transparency=X.Transparency==1 and 0 or 1 while math.floor(X.Transparency)==0 do if not game.Players:GetPlayerFromCharacter(L.Parent)then break end local c=Ray.new(X.Position,n.CFrame.lookVector*999)local G,R=game.Workspace:FindPartOnRayWithIgnoreList(c,e)if G and(G and G.Transparency>=1 or G.CanCollide==false)then table.insert(e,G)end local m=(R-X.Position).magnitude X.Mesh.Offset=Vector3.new(0,m/2,0)X.Mesh.Scale=Vector3.new(.075,m/.2,.075)if G then H.CFrame=D(R,G)H.Parent=l else H.Parent=nil end b.RenderStepped:wait()end H:Destroy()X.Transparency=1 X.Mesh.Offset=Vector3.new()X.Mesh.Scale=Vector3.new(.075,0,.075)end}}}return X


local Gun = script.Parent.Parent.Parent
local player = game.Players.LocalPlayer

local Plugins = {
	
	KeyDown = {
		{ --This is a plugin for a toggleable laser
			Key = "g"; --This is the key you press to activate the plugin
			Description = "Toggle Laser"; --This is what the description of the key will be in the controls
			Plugin = function() --This is the actual plugin function
				local Laser = Gun:WaitForChild("LaserLight") --These few lines wait for the necessary bricks/models
				local Handle = Gun:WaitForChild("Grip")
				local ignoreCode = Gun.Program_Client:WaitForChild("ignoreCode")
				local ignoreModel = game.Workspace:WaitForChild("BulletModel: " .. player.Name)
				local ignoreList = {}
				
				local PlyrName = game.Players:GetPlayerFromCharacter(Gun.Parent).Name
				local playerFolder = ignoreModel
				
				local RS = game:GetService("RunService")
				
				local function createLaserDot() --This function creates the red laser dot
					local laserDot = Instance.new("Part")
					laserDot.Transparency = 1
					laserDot.Name = "laserDot"
					laserDot.Anchored = true
					laserDot.CanCollide = false
					laserDot.FormFactor = Enum.FormFactor.Custom
					laserDot.Size = Vector3.new(0.25, 0.25, 1)
					
					local laserGui = Instance.new("SurfaceGui")
					laserGui.CanvasSize = Vector2.new(100, 100)
					laserGui.Parent = laserDot
					
					local laserImage = Instance.new("ImageLabel")
					laserImage.BackgroundTransparency = 1
					laserImage.Size = UDim2.new(1, 0, 1, 0)
					laserImage.Image = "http://www.roblox.com/asset/?id=131394739"
					laserImage.Parent = laserGui
					
					--[[local laserLight = Instance.new("SurfaceLight")
					laserLight.Angle = 180
					laserLight.Brightness = math.huge
					laserLight.Color = Color3.new(1, 0, 0)
					laserLight.Face = Enum.NormalId.Back
					laserLight.Range = 5
					laserLight.Shadows = true
					laserLight.Parent = laserDot]]
					
					return laserDot
				end
				
				local function getHitSurfaceCFrame(Pos, Obj) --This function returns the proper cframe based on the face that the position is on
					local surfaceCF = {
						{"Back", Obj.CFrame * CFrame.new(0, 0, Obj.Size.z)};
						{"Bottom", Obj.CFrame * CFrame.new(0, -Obj.Size.y, 0)};
						{"Front", Obj.CFrame * CFrame.new(0, 0, -Obj.Size.z)};
						{"Left", Obj.CFrame * CFrame.new(-Obj.Size.x, 0, 0)};
						{"Right", Obj.CFrame * CFrame.new(Obj.Size.x, 0, 0)};
						{"Top", Obj.CFrame * CFrame.new(0, Obj.Size.y, 0)}
					}
					local closestDist = math.huge
					local closestSurface = nil
					for _,v in pairs(surfaceCF) do
						local surfaceDist = (Pos - v[2].p).magnitude
						if surfaceDist < closestDist then
							closestDist = surfaceDist
							closestSurface = v
						end
					end
					
					local surfaceDir = CFrame.new(Obj.CFrame.p, closestSurface[2].p)
					local surfaceDist = surfaceDir.lookVector * ((Obj.CFrame.p - closestSurface[2].p).magnitude / 2 - 0.25)
					local surfaceOffset = Pos - closestSurface[2].p + surfaceDist
					local surfaceCFrame = surfaceDir + surfaceDist + surfaceOffset
					
					return surfaceCFrame
				end
				
				local laserDot = createLaserDot() --The code is cleaner when the laser creating code is in a function
				
				Laser.Transparency = (Laser.Transparency == 1 and 0 or 1) --Toggles the laser on or off
				
				while math.floor(Laser.Transparency) == 0 do --This loop will keep running as long as the laser is visible
					if (not game.Players:GetPlayerFromCharacter(Gun.Parent)) then break end --This checks if the gun is a child of the character
					
					local newRay = Ray.new(Laser.Position, Handle.CFrame.lookVector * 999)
					local H, P = game.Workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)
					
					if H and (H and H.Transparency >= 1 or H.CanCollide == false) then
						table.insert(ignoreList, H)
					end
					
					local Distance = (P - Laser.Position).magnitude
					Laser.Mesh.Offset = Vector3.new(0, Distance / 2, 0)
					Laser.Mesh.Scale = Vector3.new(0.075, Distance / 0.2, 0.075)
					
					if H then
						laserDot.CFrame = getHitSurfaceCFrame(P, H) --If the laser hits a part then position the dot on the part
						laserDot.Parent = playerFolder
					else
						laserDot.Parent = nil --If the laser doesn't hit a part then temporarily remove the laser dor
					end
					
					RS.RenderStepped:wait()
				end
				
				laserDot:Destroy() --These lines reset the laser if the laser is transparent or the gun was deselected
				Laser.Transparency = 1
				Laser.Mesh.Offset = Vector3.new()
				Laser.Mesh.Scale = Vector3.new(0.075, 0, 0.075)
			end;
		};
		
	};
	
}

return Plugins
