Projectile=script.Parent Projectile.Size=Vector3.new(.2,.2,.2)Players=game:GetService("\080\108\097\121\101\114\115")Debris=game:GetService("\068\101\098\114\105\115")Values={}for V,n in pairs(script:GetChildren())do if string.find(string.lower(n.ClassName),string.lower("\086\097\108\117\101"))then Values[n.Name]=n end end BaseProjectile=Values.BaseProjectile.Value function GetCreator()local V=Values.Creator.Value return(V and(V.Parent and V:IsA("\080\108\097\121\101\114")))and V or nil end function IsTeamMate(V,n)return V and(n and(not V.Neutral and(not n.Neutral and V.TeamColor==n.TeamColor)))end function TagHumanoid(V,n)local v=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")v.Name="\099\114\101\097\116\111\114"v.Value=n Debris:AddItem(v,2)v.Parent=V end function UntagHumanoid(V)for V,n in pairs(V:GetChildren())do if n:IsA("\079\098\106\101\099\116\086\097\108\117\101")and n.Name=="\099\114\101\097\116\111\114"then n:Destroy()end end end function CheckTableForString(V,n)for V,v in pairs(V)do if string.find(string.lower(n),string.lower(v))then return true end end return false end function CheckIntangible(V)local n={"\087\097\116\101\114","\080\097\114\116";"\080\114\111\106\101\099\116\105\108\101","\069\102\102\101\099\116","\082\097\105\108";"\076\097\115\101\114";"\066\117\108\108\101\116"}if V and V.Parent then if(not V.CanCollide or CheckTableForString(n,V.Name))and not V.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then return true end end return false end function CastRay(V,n,v,S,i)local P=type(S)=="\116\097\098\108\101"and S or{S}local C,K,e=(game:GetService("\087\111\114\107\115\112\097\099\101")):FindPartOnRayWithIgnoreList(Ray.new(V,n*v),P)if C and CheckIntangible(C)then if i then wait()end C,K,e=CastRay(K+n*.01,n,v-(V-K).magnitude,P,i)end return C,K,e end function FlyProjectile(V,n)local v=false local S=GetCreator()local function i(V)if not V or not V.Parent or not S then return end local n=V.Parent if n:IsA("\072\097\116")then n=n.Parent end if not n then return end local v=Players:GetPlayerFromCharacter(n)if v and(v==S or IsTeamMate(S,v))then return end local i=n:FindFirstChild("\072\117\109\097\110\111\105\100")if not i or i.Health==0 then return end UntagHumanoid(i)TagHumanoid(i,S)i:TakeDamage(Values.Damage.Value)return n end local function P(n)local v={{Vector=V.CFrame.lookVector,Length=BaseProjectile.Size.Z+2},{Vector=Vector3.new(0,-1,0);Length=BaseProjectile.Size.Y*1.25},n and{Vector=(CFrame.new(V.Position,n.Position)).lookVector,Length=BaseProjectile.Size.Z+2}or nil}local i={DistanceApart=math.huge}for n,v in pairs(v)do if v then local n=(CFrame.new(V.Position,(V.CFrame+v.Vector*2).p)).lookVector local P,C,K=CastRay(V.Position+Vector3.new(0,0,0),n,v.Length,{S and S.Character or nil;V},false)if P then local n=(V.Position-C).Magnitude if n<i.DistanceApart then i={Hit=P,Pos=C,Normal=K,DistanceApart=n}end end end end return i.Hit and i or nil end local function C(S)if v then return end local C=P(S)if not C then return end v=true for V,n in pairs(V:GetChildren())do if n:IsA("\066\097\115\101\080\097\114\116")then for V,v in pairs(n:GetChildren())do if v:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then v.Enabled=false n.Anchored=true elseif v:IsA("\074\111\105\110\116\073\110\115\116\097\110\099\101")then v:Destroy()end end Debris:AddItem(n,8)elseif string.find(string.lower(n.ClassName),string.lower("\066\111\100\121"))then n:Destroy()end end local K=i(C.Hit)V.Size=Vector3.new(.2,.2,.2)V.CanCollide=false local e=C.Hit if K and e.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")or e.Parent.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then script.HitE:Fire(e)if Values.ProjectileLand.Value==true then local v=C.Pos local S=CFrame.new(v,n)S=(S*CFrame.new(0,0,-(BaseProjectile.Size.Z/2)+0))*CFrame.Angles(0,math.pi,0)local i=Instance.new("\077\111\116\111\114\054\068")i.Part0=e i.Part1=V i.C0=CFrame.new(0,0,0)i.C1=S:inverse()*e.CFrame i.Parent=V V.Orientation=V.Orientation+Values.ProjectileLandRotation.Value else script.Parent:Destroy()end else script.HitE:Fire(e)if Values.ProjectileLand.Value==true then local v=C.Pos local S=CFrame.new(v,n)S=(S*CFrame.new(0,0,-(BaseProjectile.Size.Z/2)+0))*CFrame.Angles(0,math.pi,0)local i=Instance.new("\077\111\116\111\114\054\068")i.Part0=e i.Part1=V i.C0=CFrame.new(0,0,0)i.C1=S:inverse()*e.CFrame i.Parent=V V.Orientation=V.Orientation+Values.ProjectileLandRotation.Value else script.Parent:Destroy()end end delay(Values.Lifetime.Value,function()Projectile:Destroy()end)V.Name="\069\102\102\101\099\116"end V.Touched:connect(function(V)if not V or not V.Parent or v then return end C(V)end)spawn(function()while V and(V.Parent and(V.Name~="\069\102\102\101\099\116"and not v))do C()wait()end end)end FlyProjectile(Projectile,Values.Origin.Value)


Projectile = script.Parent
Projectile.Size = Vector3.new(0.2,0.2,0.2)

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

Values = {}
for i, v in pairs(script:GetChildren()) do
	if string.find(string.lower(v.ClassName), string.lower("Value")) then
		Values[v.Name] = v
	end
end

BaseProjectile = Values.BaseProjectile.Value

function GetCreator()
	local Creator = Values.Creator.Value
	return (((Creator and Creator.Parent and Creator:IsA("Player")) and Creator) or nil)
end

function IsTeamMate(Player1, Player2)
	return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
end

function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

function UntagHumanoid(humanoid)
	for i, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

function CheckTableForString(Table, String)
	for i, v in pairs(Table) do
		if string.find(string.lower(String), string.lower(v)) then
			return true
		end
	end
	return false
end

function CheckIntangible(Hit)
	local ProjectileNames = {"Water", "Part", "Projectile", "Effect", "Rail", "Laser", "Bullet"}
	if Hit and Hit.Parent then
		if ((not Hit.CanCollide or CheckTableForString(ProjectileNames, Hit.Name)) and not Hit.Parent:FindFirstChild("Humanoid")) then
			return true
		end
	end
	return false
end

function CastRay(StartPos, Vec, Length, Ignore, DelayIfHit)
	local Ignore = ((type(Ignore) == "table" and Ignore) or {Ignore})
	local RayHit, RayPos, RayNormal = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(Ray.new(StartPos, Vec * Length), Ignore)
	if RayHit and CheckIntangible(RayHit) then
		if DelayIfHit then
			wait()
		end
		RayHit, RayPos, RayNormal = CastRay((RayPos + (Vec * 0.01)), Vec, (Length - ((StartPos - RayPos).magnitude)), Ignore, DelayIfHit)
	end
	return RayHit, RayPos, RayNormal
end

function FlyProjectile(Part, StartPos)
	local AlreadyHit = false
	local Player = GetCreator()
	local function PartHit(Hit)
		if not Hit or not Hit.Parent or not Player then
			return
		end
		local character = Hit.Parent
		if character:IsA("Hat") then
			character = character.Parent
		end
		if not character then
			return
		end
		local player = Players:GetPlayerFromCharacter(character)
		if player and (player == Player or IsTeamMate(Player, player)) then
			return
		end
		local humanoid = character:FindFirstChild("Humanoid")
		if not humanoid or humanoid.Health == 0 then
			return
		end
		UntagHumanoid(humanoid)
		TagHumanoid(humanoid, Player)
		humanoid:TakeDamage(Values.Damage.Value)
		return character
	end
	local function CheckForContact(Hit)
		local Directions = {{Vector = Part.CFrame.lookVector, Length = (BaseProjectile.Size.Z + 2)}, {Vector = Vector3.new(0, -1, 0), Length = (BaseProjectile.Size.Y * 1.25)}, ((Hit and {Vector = CFrame.new(Part.Position, Hit.Position).lookVector, Length = (BaseProjectile.Size.Z + 2)}) or nil)}
		local ClosestRay = {DistanceApart = math.huge}
		for i, v in pairs(Directions) do
			if v then
				local Direction = CFrame.new(Part.Position, (Part.CFrame + v.Vector * 2).p).lookVector
				local RayHit, RayPos, RayNormal = CastRay((Part.Position + Vector3.new(0, 0, 0)), Direction, v.Length, {((Player and Player.Character) or nil), Part}, false)
				if RayHit then
					local DistanceApart = (Part.Position - RayPos).Magnitude
					if DistanceApart < ClosestRay.DistanceApart then
						ClosestRay = {Hit = RayHit, Pos = RayPos, Normal = RayNormal, DistanceApart = DistanceApart}
					end
				end
			end
		end
		return ((ClosestRay.Hit and ClosestRay) or nil)
	end
	local function ConnectPart(Hit)
		
		if AlreadyHit then
			return
		end
		local ClosestRay = CheckForContact(Hit)
		if not ClosestRay then
			return
		end
		AlreadyHit = true
		for i, v in pairs(Part:GetChildren()) do
			if v:IsA("BasePart") then
				for ii, vv in pairs(v:GetChildren()) do
					if vv:IsA("ParticleEmitter") then
						vv.Enabled = false
						v.Anchored = true
					elseif vv:IsA("JointInstance") then
						vv:Destroy()
					end
				end
				Debris:AddItem(v, 8)
			elseif string.find(string.lower(v.ClassName), string.lower("Body")) then
				v:Destroy()
			end
		end
		local SuccessfullyHit = PartHit(ClosestRay.Hit)
		Part.Size = Vector3.new(0.2, 0.2, 0.2)
		Part.CanCollide = false
		local Hit = ClosestRay.Hit
		if SuccessfullyHit and Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent.Parent:FindFirstChild("Humanoid") then
			script.HitE:Fire(Hit)
			if Values.ProjectileLand.Value == true then
				local ProjectilePosition = ClosestRay.Pos
				local StickCFrame = CFrame.new(ProjectilePosition, StartPos)
				StickCFrame = (StickCFrame * CFrame.new(0, 0, (-(BaseProjectile.Size.Z / 2) + 0)) * CFrame.Angles(0, math.pi, 0))
				local Weld = Instance.new("Motor6D")
				Weld.Part0 = Hit
				Weld.Part1 = Part
				Weld.C0 = CFrame.new(0, 0, 0)
				Weld.C1 = (StickCFrame:inverse() * Hit.CFrame)
				Weld.Parent = Part
				Part.Orientation = Part.Orientation + Values.ProjectileLandRotation.Value
			else
				script.Parent:Destroy()
			end
		else
			script.HitE:Fire(Hit)
			if Values.ProjectileLand.Value == true then
				local ProjectilePosition = ClosestRay.Pos
				local StickCFrame = CFrame.new(ProjectilePosition, StartPos)
				StickCFrame = (StickCFrame * CFrame.new(0, 0, (-(BaseProjectile.Size.Z / 2) + 0)) * CFrame.Angles(0, math.pi, 0))
				local Weld = Instance.new("Motor6D")
				Weld.Part0 = Hit
				Weld.Part1 = Part
				Weld.C0 = CFrame.new(0, 0, 0)
				Weld.C1 = (StickCFrame:inverse() * Hit.CFrame)
				Weld.Parent = Part
				Part.Orientation = Part.Orientation + Values.ProjectileLandRotation.Value
			else
				script.Parent:Destroy()
			end
		end
		delay(Values.Lifetime.Value,function()
			Projectile:Destroy()
		end)
		Part.Name = "Effect"
	end
	Part.Touched:connect(function(Hit)
		if not Hit or not Hit.Parent or AlreadyHit then
			return
		end
		ConnectPart(Hit)
	end)
	spawn(function()
		while Part and Part.Parent and Part.Name ~= "Effect" and not AlreadyHit do
			ConnectPart()
			wait()
		end
	end)
end

FlyProjectile(Projectile, Values.Origin.Value)
