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.Clamp(A,O,s)return math.max(math.min(s,A),O)end function Functions.GetPercentage(A,O,s)return((s-A)/(O-A))*100 end function Functions.Round(A,O)local s,W=math.modf(A)return W>=O and math.ceil(A)or W<O and math.floor(A)end function Functions.IsTeamMate(A,O)return A and(O and(not A.Neutral and(not O.Neutral and A.TeamColor==O.TeamColor)))end function Functions.TagHumanoid(A,O)local s=(Create("\079\098\106\101\099\116\086\097\108\117\101"))({Name="\099\114\101\097\116\111\114",Value=O})Debris:AddItem(s,2)s.Parent=A end function Functions.UntagHumanoid(A)for A,O in pairs(A:GetChildren())do if O:IsA("\079\098\106\101\099\116\086\097\108\117\101")and O.Name=="\099\114\101\097\116\111\114"then O:Destroy()end end end function Functions.CheckTableForString(A,O)for A,s in pairs(A)do if string.find(string.lower(O),string.lower(s))then return true end end return false end function Functions.CheckIntangible(A)local O={"\087\097\116\101\114","\065\114\114\111\119";"\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 A and A.Parent then if(not A.CanCollide or A.Parent:IsA("\072\097\116")or Functions.CheckTableForString(O,A.Name))and not A.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then return true end end return false end function Functions.CastRay(A,O,s,W,q)local U=type(W)=="\116\097\098\108\101"and W or{W}local P,Y,R=(game:GetService("\087\111\114\107\115\112\097\099\101")):FindPartOnRayWithIgnoreList(Ray.new(A,O*s),U)if P and Functions.CheckIntangible(P)then if q then wait()end P,Y,R=Functions.CastRay(Y+O*.01,O,s-(A-Y).magnitude,U,q)end return P,Y,R end function Functions.CheckTableForInstance(A,O)for A,s in pairs(A)do if s==O then return true end end return false end function Functions.GetAllConnectedParts(A)local O={}local function s(A)for A,W in pairs(A:GetConnectedParts())do local q=false if not Functions.CheckTableForInstance(O,W)then table.insert(O,W)s(W)end end end s(A)return O end function GetTotalParts(A,O,s)if A<O then return A elseif s>=A then return 0 elseif A>=O then local W=A-O if s<=A then W=A-s if W>O then return O else return W end elseif W>=O then return O else return W end end end function Functions.GetParts(A,O,s)local W={}local q=false while#W<O and not q do local U=A local P=GetTotalParts(O,100,#W)local Y=(game:GetService("\087\111\114\107\115\112\097\099\101")):FindPartsInRegion3WithIgnoreList(U,s,P)if#Y==0 then q=true else for A,O in pairs(Y)do table.insert(W,O)table.insert(s,O)end end end return W end return Functions


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

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

Functions = {}

function Functions.Clamp(Number, Min, Max)
	return math.max(math.min(Max, Number), Min)
end

function Functions.GetPercentage(Start, End, Number)
	return (((Number - Start) / (End - Start)) * 100)
end

function Functions.Round(Number, RoundDecimal)
	local WholeNumber, Decimal = math.modf(Number)
	return ((Decimal >= RoundDecimal and math.ceil(Number)) or (Decimal < RoundDecimal and math.floor(Number)))
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.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.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 = {"Water", "Arrow", "Projectile", "Effect", "Rail", "Laser", "Bullet"}
	if Hit and Hit.Parent then
		if ((not Hit.CanCollide or Hit.Parent:IsA("Hat") or Functions.CheckTableForString(ProjectileNames, Hit.Name)) and not Hit.Parent:FindFirstChild("Humanoid")) 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.CheckTableForInstance(Table, Instance)
	for i, v in pairs(Table) do
		if v == Instance then
			return true
		end
	end
	return false
end

function Functions.GetAllConnectedParts(Object)
	local Parts = {}
	local function GetConnectedParts(Object)
		for i, v in pairs(Object:GetConnectedParts()) do
			local Ignore = false
			if not Functions.CheckTableForInstance(Parts, v) then
				table.insert(Parts, v)
				GetConnectedParts(v)
			end
		end
	end
	GetConnectedParts(Object)
	return Parts
end
	
function 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 = 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

return Functions
