Players=game:GetService("\080\108\097\121\101\114\115")Debris=game:GetService("\068\101\098\114\105\115")RbxUtility=LoadLibrary("\082\098\120\085\116\105\108\105\116\121")Create=RbxUtility.Create Functions={}function Functions.TagHumanoid(M,Z)local U=(Create("\079\098\106\101\099\116\086\097\108\117\101"))({Name="\099\114\101\097\116\111\114",Value=Z})Debris:AddItem(U,2)U.Parent=M end function Functions.UntagHumanoid(M)for M,Z in pairs(M:GetChildren())do if Z:IsA("\079\098\106\101\099\116\086\097\108\117\101")and Z.Name=="\099\114\101\097\116\111\114"then Z:Destroy()end end end function Functions.IsTeamMate(M,Z)return M and(Z and(not M.Neutral and(not Z.Neutral and M.TeamColor==Z.TeamColor)))end function Functions.CheckTableForString(M,Z)for M,U in pairs(M)do if string.find(string.lower(Z),string.lower(U))then return true end end return false end function Functions.CheckIntangible(M)local Z={"\076\105\103\104\116\110\105\110\103";"\069\102\102\101\099\116";"\080\114\111\106\101\099\116\105\108\101","\065\114\114\111\119","\066\117\108\108\101\116";"\087\097\116\101\114"}if M and M.Parent then local U for M,Z in pairs(M.Parent:GetChildren())do if Z:IsA("\072\117\109\097\110\111\105\100")then U=Z break end end if not U and(not M.CanCollide and M.Transparency>=1 or Functions.CheckTableForString(Z,M.Name)or M.Parent:IsA("\072\097\116")or M.Parent:IsA("\084\111\111\108"))then return true end end return false end function Functions.CastRay(M,Z,U,v,u)local y=type(v)=="\116\097\098\108\101"and v or{v}local A,C,l=(game:GetService("\087\111\114\107\115\112\097\099\101")):FindPartOnRayWithIgnoreList(Ray.new(M,Z*U),y)if A and Functions.CheckIntangible(A)then if u then wait()end A,C,l=Functions.CastRay(C+Z*.01,Z,U-(M-C).magnitude,y,u)end return A,C,l end function Functions.GetTotalParts(M,Z,U)if M<Z then return M elseif U>=M then return 0 elseif M>=Z then local v=M-Z if U<=M then v=M-U if v>Z then return Z else return v end elseif v>=Z then return Z else return v end end end function Functions.GetParts(M,Z,U)local v={}local u=false while#v<Z and not u do local y=M local A=Functions.GetTotalParts(Z,100,#v)local C=(game:GetService("\087\111\114\107\115\112\097\099\101")):FindPartsInRegion3WithIgnoreList(y,U,A)if#C==0 then u=true else for M,Z in pairs(C)do table.insert(v,Z)table.insert(U,Z)end end end return v end function Functions.CheckTableForInstance(M,Z)for M,U in pairs(M)do if U==Z then return true end end return false end return Functions


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

RbxUtility = LoadLibrary("RbxUtility")
Create = RbxUtility.Create

Functions = {}

function Functions.TagHumanoid(humanoid, player)
	local Creator_Tag = Create("ObjectValue"){
		Name = "creator",
		Value = player,
	}
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

function Functions.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 Functions.IsTeamMate(Player1, Player2)
	return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
end

function Functions.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 Functions.CheckIntangible(Hit)
	local ProjectileNames = {"Lightning", "Effect", "Projectile", "Arrow", "Bullet", "Water"}
	if Hit and Hit.Parent then
		local HumanoidFound
		for i, v in pairs(Hit.Parent:GetChildren()) do
			if v:IsA("Humanoid") then
				HumanoidFound = v
				break
			end
		end
		if not HumanoidFound and ((not Hit.CanCollide and Hit.Transparency >= 1) or Functions.CheckTableForString(ProjectileNames, Hit.Name) or Hit.Parent:IsA("Hat") or Hit.Parent:IsA("Tool")) then
			return true
		end
	end
	return false
end

function Functions.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 Functions.CheckIntangible(RayHit) then
		if DelayIfHit then
			wait()
		end
		RayHit, RayPos, RayNormal = Functions.CastRay((RayPos + (Vec * 0.01)), Vec, (Length - ((StartPos - RayPos).magnitude)), Ignore, DelayIfHit)
	end
	return RayHit, RayPos, RayNormal
end

function Functions.GetTotalParts(MaxParts, PossibleParts, Parts)
	if MaxParts < PossibleParts then
		return MaxParts
	elseif Parts >= MaxParts then
		return 0
	elseif MaxParts >= PossibleParts then
		local PartCount = (MaxParts - PossibleParts)
		if Parts <= MaxParts then
			PartCount = (MaxParts - Parts)
			if PartCount > PossibleParts then
				return PossibleParts
			else
				return PartCount
			end
		elseif PartCount >= PossibleParts then
			return PossibleParts
		else
			return PartCount
		end
	end
end

function Functions.GetParts(Region, MaxParts, Ignore)
	local Parts = {}
	local RerunFailed = false
	while #Parts < MaxParts and not RerunFailed do
		local Region = Region
		local PossibleParts = Functions.GetTotalParts(MaxParts, 100, #Parts)
		local PartsNearby = game:GetService("Workspace"):FindPartsInRegion3WithIgnoreList(Region, Ignore, PossibleParts)
		if #PartsNearby == 0 then
			RerunFailed = true
		else
			for i, v in pairs(PartsNearby) do
				table.insert(Parts, v)
				table.insert(Ignore, v)
			end
		end
	end
	return Parts
end

function Functions.CheckTableForInstance(Table, Instance)
	for i, v in pairs(Table) do
		if v == Instance then
			return true
		end
	end
	return false
end

return Functions
