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