local X={Duration=0,MaxDuration=5,LinkDamage=10}local l,x,I=script.FindFirstChild,script.FindFirstChildOfClass,script.WaitForChild local Q,U=script.Clone,script.Destroy local a=I(script,"\072\097\110\100\108\101\082\101\102",5)local W=I(script,"\067\114\101\097\116\111\114",5)local O=I(script,"\073\110\105\116\105\097\108\084\097\114\103\101\116",5)if not O or not O.Value or not a or not a.Value or not W then script:Destroy()end a=a.Value W=W.Value O=O.Value local S=l(O.Parent,"\084\111\114\115\111")or l(O.Parent,"\085\112\112\101\114\084\111\114\115\111")local t=x(W.Character,"\072\117\109\097\110\111\105\100")local T=game:FindService("\080\108\097\121\101\114\115")or game:GetService("\080\108\097\121\101\114\115")local C=game:FindService("\068\101\098\114\105\115")or game:GetService("\068\101\098\114\105\115")local f=game:FindService("\082\117\110\083\101\114\118\105\099\101")or game:GetService("\082\117\110\083\101\114\118\105\099\101")print("\083\116\097\114\108\105\103\104\116 \076\105\110\107 \097\098\105\108\105\116\121 \097\099\116\105\118\097\116\101\100\033 \084\097\103 \097\115 \109\117\099\104 \112\101\111\112\108\101 \097\115 \121\111\117 \099\097\110 \098\101\102\111\114\101 "..(X.MaxDuration.." \115\101\099\111\110\100\115 \105\115 \117\112\033"))local B=Ray.new local b,i=script.GetChildren,script.GetDescendants local M=script.IsA function IsTeamMate(X,l)return X and(l and(not X.Neutral and(not l.Neutral and X.TeamColor==l.TeamColor)))end function TagHumanoid(X,l)local x=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")x.Name="\099\114\101\097\116\111\114"x.Value=l C:AddItem(x,2)x.Parent=X end function UntagHumanoid(X)for X,l in pairs(b(X))do if M(l,"\079\098\106\101\099\116\086\097\108\117\101")and l.Name=="\099\114\101\097\116\111\114"then U(l)end end end local q,u={},{}local K=Instance.new("\078\117\109\098\101\114\086\097\108\117\101")K.Value=X.Duration K.Name="\068\117\114\097\116\105\111\110"K.Parent=script local j=Instance.new("\065\116\116\097\099\104\109\101\110\116")q[#q+1]=j j.Name="\067\111\110\115\116\101\108\108\097\116\105\111\110\095\076\105\110\107"j.Position=Vector3.new(0,0,0)j.Parent=S local c=ColorSequence.new local v,J=Color3.fromRGB(0,170,255),Color3.new(1,1,1)local Z,E,R={},{},{}local H={}pcall(function()local l=Q(script.Sparkle_Large_Blue)R[#R+1]=l q[#q+1]=l l.Parent=S l.Enabled=true u[#u+1]=(K:GetPropertyChangedSignal("\086\097\108\117\101")):Connect(function()l.Color=c(v:Lerp(J,X.Duration/X.MaxDuration),J)end)end)pcall(function()local X=Q(script.ExplodeSound)H[#H+1]=X X.Parent=j end)local y=j local e,D={},{}D[O]=O local N=1 Z[#Z+1]=O E[#E+1]=j function Link(I)if not I or not I.Parent then return end e[1]=I local U=B(a.Position,((I.Position-a.Position).Unit*math.max(a.Size.X,a.Size.Y,a.Size.Z))*2)local O=workspace:FindPartOnRayWithWhitelist(U,e,true)if O~=I then return end local S,C,f=x(I.Parent,"\070\111\114\099\101\070\105\101\108\100"),x(I.Parent,"\072\117\109\097\110\111\105\100"),l(I.Parent,"\084\111\114\115\111")or l(I.Parent,"\085\112\112\101\114\084\111\114\115\111")if S or not C or not f or C==t or C.Health<=0 or D[C]then return end if IsTeamMate(W,T:GetPlayerFromCharacter(C.Parent))then return end D[C]=C Z[#Z+1]=C j=Instance.new("\065\116\116\097\099\104\109\101\110\116")E[#E+1]=j pcall(function()local X=Q(script.ExplodeSound)H[#H+1]=X X.Parent=j end)q[#q+1]=j j.Name="\067\111\110\115\116\101\108\108\097\116\105\111\110\095\076\105\110\107"j.Position=Vector3.new(0,0,0)if y then pcall(function()local l=Q(script.Constellation_Beam)q[#q+1]=l l.Attachment0=y l.Attachment1=j l.Enabled=true l.Parent=j u[#u+1]=(K:GetPropertyChangedSignal("\086\097\108\117\101")):Connect(function()l.Color=c(v:Lerp(J,X.Duration/X.MaxDuration))end)end)end pcall(function()local l=Q(script.Sparkle_Large_Blue)q[#q+1]=l R[#R+1]=l l.Parent=f l.Enabled=true u[#u+1]=(K:GetPropertyChangedSignal("\086\097\108\117\101")):Connect(function()l.Color=c(v:Lerp(J,X.Duration/X.MaxDuration),J)end)end)j.Parent=f y=j N=N+1 X.Duration=0 end a.Touched:Connect(Link)local z=false while X.Duration<X.MaxDuration and not z do local l=f.Heartbeat:Wait()X.Duration=X.Duration+l K.Value=X.Duration end


local Properties = {
	Duration = 0, -- The current time the ability is active
	MaxDuration = 5, -- How long can the ability delay itself before it fully executes.
	LinkDamage = 10 -- The amount of damage multiplied per-person linked.
}

local FindFirstChild, FindFirstChildOfClass, WaitForChild = script.FindFirstChild, script.FindFirstChildOfClass, script.WaitForChild

local Clone, Destroy = script.Clone, script.Destroy

local Handle = WaitForChild(script, "HandleRef", 5)
local Creator = WaitForChild(script, "Creator", 5)
local InitialTarget = WaitForChild(script, "InitialTarget", 5)

if not InitialTarget or not InitialTarget.Value or not Handle or not Handle.Value or not Creator then script:Destroy() end

Handle = Handle.Value
Creator = Creator.Value
InitialTarget = InitialTarget.Value

local TargetTorso = (FindFirstChild(InitialTarget.Parent, "Torso") or FindFirstChild(InitialTarget.Parent, "UpperTorso"))

local Humanoid = FindFirstChildOfClass(Creator.Character, "Humanoid")

local Players = (game:FindService("Players") or game:GetService("Players"))
local Debris = (game:FindService("Debris") or game:GetService("Debris"))
local RunService = (game:FindService("RunService") or game:GetService("RunService"))

print("Starlight Link ability activated! Tag as much people as you can before " .. Properties.MaxDuration .. " seconds is up!")

local NewRay = Ray.new

local GetChildren, GetDescendants = script.GetChildren, script.GetDescendants

local IsA = script.IsA

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(GetChildren(humanoid)) do
		if IsA(v,"ObjectValue") and v.Name == "creator" then
			Destroy(v)
		end
	end
end

local Deletables, Events = {}, {} --Put objects in the tables to discard when we're done.

local DurationValue = Instance.new("NumberValue")
DurationValue.Value = Properties.Duration
DurationValue.Name = "Duration"
DurationValue.Parent = script

local Attach = Instance.new("Attachment")
Deletables[#Deletables+1] = Attach
	
Attach.Name = "Constellation_Link"
Attach.Position = Vector3.new(0,0,0)

Attach.Parent = TargetTorso

local NewColorSequence = ColorSequence.new
local Color_1, Color_2 = Color3.fromRGB(0,170,255), Color3.new(1,1,1)

local Queue, AttachQueue, SparkleQueue = {}, {}, {}
local Sounds = {}
pcall(function()
		
	local Sparkles = Clone(script["Sparkle_Large_Blue"])
	SparkleQueue[#SparkleQueue+1] = Sparkles
	Deletables[#Deletables+1] = Sparkles
		
	Sparkles.Parent = TargetTorso
		
	Sparkles.Enabled = true
	
	Events[#Events+1] = DurationValue:GetPropertyChangedSignal("Value"):Connect(function()
		Sparkles.Color = NewColorSequence(Color_1:Lerp(Color_2, Properties.Duration/Properties.MaxDuration), Color_2)
	end)
	
end)

pcall(function()
	local ExplodeSound = Clone(script.ExplodeSound)
	Sounds[#Sounds+1] = ExplodeSound
	ExplodeSound.Parent = Attach
end)
	
local LastAttachment = Attach --Reference the last attachment point we made.

local Hit_WhiteList, TaggedHumanoids = {}, {}
TaggedHumanoids[InitialTarget] = InitialTarget
local Total = 1





Queue[#Queue+1] = InitialTarget
AttachQueue[#AttachQueue+1] = Attach

function Link(hit)
	
	if not hit or not hit.Parent then return end
	
	Hit_WhiteList[1] = hit --Replace the Whitelisted entry (Also helps reduce lag)
	
	--Do a Server-sided check to make sure the sword is in reasonable distance to the part hit (To prevent exploits)
	
	local DistanceRay = NewRay( Handle.Position , (hit.Position - Handle.Position).Unit * math.max(Handle.Size.X,Handle.Size.Y,Handle.Size.Z) * 2 )
	
	local part = workspace:FindPartOnRayWithWhitelist(DistanceRay, Hit_WhiteList , true)	
	
	--warn((part and "Part in range") or "Part not in range")
	--assert(part, "Part not in range: Potential exploit")
	if part ~= hit then return end -- Potential exploiter may be abusing the touched events
	
	local FF, Hum, Torso = FindFirstChildOfClass(hit.Parent, "ForceField"), FindFirstChildOfClass(hit.Parent, "Humanoid"), (FindFirstChild(hit.Parent, "Torso") or FindFirstChild(hit.Parent, "UpperTorso"))
	
	if FF or not Hum or not Torso or Hum == Humanoid or Hum.Health <= 0 or TaggedHumanoids[Hum] then return end --Don't hit yourself or anyone with a ForceField now..
	
	if IsTeamMate(Creator, Players:GetPlayerFromCharacter(Hum.Parent)) then return end
	
	TaggedHumanoids[Hum] = Hum --We got one!
	
	Queue[#Queue+1] = Hum
	
	Attach = Instance.new("Attachment")
	AttachQueue[#AttachQueue+1] = Attach
	
	pcall(function()
		local ExplodeSound = Clone(script.ExplodeSound)
		Sounds[#Sounds+1] = ExplodeSound
		ExplodeSound.Parent = Attach
	end)
	
	
	Deletables[#Deletables+1] = Attach
	
	Attach.Name = "Constellation_Link"
	Attach.Position = Vector3.new(0,0,0)
	
	--warn(LastAttachment)
	
	if LastAttachment then
		--Create a Constellation Beam from one target to another
		pcall(function()
			
			local Constellation_Beam = Clone(script["Constellation_Beam"])
			Deletables[#Deletables+1] = Constellation_Beam
			
			Constellation_Beam.Attachment0 = LastAttachment
			Constellation_Beam.Attachment1 = Attach
			Constellation_Beam.Enabled = true
			
			Constellation_Beam.Parent = Attach
			
			Events[#Events+1] = DurationValue:GetPropertyChangedSignal("Value"):Connect(function()
				Constellation_Beam.Color = NewColorSequence(Color_1:Lerp(Color_2, Properties.Duration/Properties.MaxDuration))
			end)
					
			--print("Linked Targets!")
			
		end)
		
	end
	
	pcall(function()
		
		local Sparkles = Clone(script["Sparkle_Large_Blue"])
		Deletables[#Deletables+1] = Sparkles
		SparkleQueue[#SparkleQueue+1] = Sparkles
		
		Sparkles.Parent = Torso
		
		Sparkles.Enabled = true
		
		Events[#Events+1] = DurationValue:GetPropertyChangedSignal("Value"):Connect(function()
			Sparkles.Color = NewColorSequence(Color_1:Lerp(Color_2, Properties.Duration/Properties.MaxDuration), Color_2)
		end)
		
	end)
	
	Attach.Parent = Torso
	
	LastAttachment = Attach --Reference the last attachment point we made.
	
	Total = Total + 1
	
	--warn("Tagged " .. Hum.Parent.Name .. "!", "\n Pending damage: " .. Properties.LinkDamage * Total)
	
	Properties.Duration = 0 --Reset the duration for every time you've tagged a person.
	
end

Handle.Touched:Connect(Link)
local Canceled = false

while Properties.Duration < Properties.MaxDuration and not Canceled do
	local delta = RunService.Heartbeat:Wait()
	Properties.Duration = Properties.Duration + delta
	DurationValue.Value = Properties.Duration
	--print(Properties.Duration)
end
