local l={Damage=8,Special=true;SpecialReload=30;SpecialActive=false;TimetoChange=12;LightTeleport=true}local Q={Lunge=Handle:WaitForChild("\076\117\110\103\101");Unsheath=Handle:WaitForChild("\085\110\115\104\101\097\116\104")}local x=Tool:FindFirstChildOfClass("\082\101\109\111\116\101\069\118\101\110\116")or(Create("\082\101\109\111\116\101\069\118\101\110\116"))({Name="\082\101\109\111\116\101";Parent=Tool})local V=Tool:FindFirstChildOfClass("\082\101\109\111\116\101\070\117\110\099\116\105\111\110")or(Create("\082\101\109\111\116\101\070\117\110\099\116\105\111\110"))({Name="\077\111\117\115\101\073\110\112\117\116",Parent=Tool})local function p(l)local Q=Services.Lighting:GetSunDirection()if(Vector3.new(0,1,0)):Dot(Q)>0 then local x=workspace:FindPartOnRay(Ray.new(Handle.Position,Q*999),l)if not x or x and not x.CanCollide then return true end end return false end function IsInTable(l,Q)for l,x in pairs(l)do if x==Q then return true end end return false end local function f(l)local Q=tick()repeat Services.RunService.Stepped:Wait()until tick()-Q>=l end function IsTeamMate(l,Q)return l and(Q and(not l.Neutral and(not Q.Neutral and l.TeamColor==Q.TeamColor)))end function TagHumanoid(l,Q)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=Q Services.Debris:AddItem(x,2)x.Parent=l end function UntagHumanoid(l)for l,Q in pairs(l:GetChildren())do if Q:IsA("\079\098\106\101\099\116\086\097\108\117\101")and Q.Name=="\099\114\101\097\116\111\114"then Q:Destroy()end end end local function H(l)for Q,x in pairs(Handle:GetDescendants())do if x:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")and x.Parent~=Handle or x:IsA("\076\105\103\104\116")then x.Enabled=l end if x:IsA("\076\105\103\104\116")then x.Range=l and 10 or 3 end end end local function s(l)for Q,x in pairs(Handle:GetDescendants())do if x:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")and x.Parent==Handle then x.Enabled=l end if x:IsA("\066\101\097\109")then x.TextureSpeed=l and 1 or.1 x.Color=l and ColorSequence.new(Color3.new(1,1,1))or ColorSequence.new(Color3.new(.5,.5,.5))end end end local B,z,W,F function PassiveSpecial()if not W or W.Health<=0 or not z then return end if not p(z)then H(false)l.SpecialActive=false if W and Tool:IsDescendantOf(z)then W.WalkSpeed=16 l.Damage=14 end return end if W and Tool:IsDescendantOf(z)then W.WalkSpeed=25 l.Damage=20 end if not z:FindFirstChild((script:WaitForChild("\083\111\076\068\101\102\101\110\115\101")).Name)and Tool:IsDescendantOf(z)then local l=(script:WaitForChild("\083\111\076\068\101\102\101\110\115\101")):Clone()local Q=(Create("\079\098\106\101\099\116\086\097\108\117\101"))({Name="\084\111\111\108\082\101\102",Value=Tool;Parent=l})l.Parent=z l.Disabled=false end if l.SpecialActive then return end l.SpecialActive=true H(true)end local S={}function ChangeTime(Q)if not l.Special then return end l.Special=false s(false)Tool.Enabled=false W.WalkSpeed=0 S.Summon:Play()delay(3,function()PassiveSpecial()Tool.Enabled=true S.Summon:Stop()end)delay(l.SpecialReload,function()l.Special=true s(true)end)local x=(script:WaitForChild("\084\105\109\101\067\104\097\110\103\101")):Clone()local V=(Create("\086\101\099\116\111\114\051\086\097\108\117\101"))({Name="\083\112\097\119\110\080\111\115\105\116\105\111\110";Value=F.Position-Vector3.new(0,F.Size.Y*1.5,0);Parent=x})local p=(Create("\079\098\106\101\099\116\086\097\108\117\101"))({Name="\067\114\101\097\116\111\114";Value=B;Parent=x})local f=(Create("\078\117\109\098\101\114\086\097\108\117\101"))({Name="\084\105\109\101",Value=Q;Parent=x})x.Parent=Services.ServerScriptService x.Disabled=false end local function t()local Q=script:WaitForChild("\076\105\103\104\116\087\097\114\112")local function x()local l=Services.ServerScriptService:GetChildren()for x=1,#l,1 do if l[x]and(l[x].Name==Q.Name and(l[x]:FindFirstChild("\067\104\097\114\097\099\116\101\114")and(l[x]:FindFirstChild("\067\104\097\114\097\099\116\101\114")).Value==z))then return true end end return false end if x()then return end local p,f=pcall(function()return V:InvokeClient(B)end)f=p and f or Vector3.new(0,0,0)Q=Q:Clone()local H=(Create("\079\098\106\101\099\116\086\097\108\117\101"))({Name="\067\104\097\114\097\099\116\101\114",Value=z;Parent=Q})local s=(Create("\086\101\099\116\111\114\051\086\097\108\117\101"))({Name="\084\097\114\103\101\116\076\111\099\097\116\105\111\110";Value=f;Parent=Q})local W=(Create("\078\117\109\098\101\114\086\097\108\117\101"))({Name="\082\097\110\103\101";Value=l.SpecialActive and 200 or 100,Parent=Q})Q.Parent=Services.ServerScriptService Q.Disabled=false end local R={}local K local n=false local v,e,i,r function Equipped()z=Tool.Parent B=Services.Players:GetPlayerFromCharacter(z)W=z:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")F=z:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if not W or W.Health<=0 then return end S=(Tool:WaitForChild("\065\110\105\109\097\116\105\111\110\115")):WaitForChild(W.RigType.Name)S={Slash=W:LoadAnimation(S:WaitForChild("\083\108\097\115\104\065\110\105\109")),Stab=W:LoadAnimation(S:WaitForChild("\083\116\097\098\065\110\105\109"));Summon=W:LoadAnimation(S:WaitForChild("\083\117\109\109\111\110\065\110\105\109"));Charge=W:LoadAnimation(S:WaitForChild("\067\104\097\114\103\101\065\110\105\109"))}K=Handle.Touched:Connect(function(Q)if not Q or not Q.Parent then return end local x,V=Q.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100"),Q.Parent:FindFirstChildOfClass("\070\111\114\099\101\070\105\101\108\100")if not x or V or x.Health<=0 or IsTeamMate(Services.Players:GetPlayerFromCharacter(x.Parent),B)or x.Parent==z then return end UntagHumanoid(x)TagHumanoid(x,B)x:TakeDamage(l.Damage)print(l.Damage)end)PassiveSpecial()Q.Unsheath:Play()end function Unequipped()n=false if K then K:Disconnect()K=nil end for l,Q in pairs(S)do if Q then Q:Stop()end end if v then v:Destroy()end if Tool:IsDescendantOf(workspace)and not Tool:IsDescendantOf(z)then for l=1,#R,1 do if R[l]then R[l]:Disconnect()R[l]=nil end end end end local j=Random.new()function Activated()if not Tool.Enabled or n then return end n=true S.Charge:Play()end function Deactivated()if not Tool.Enabled or not n then return end n=false Tool.Enabled=false local l=z:FindFirstChild("\082\105\103\104\116 \065\114\109")or z:FindFirstChild("\082\105\103\104\116\072\097\110\100")if l then e=l:FindFirstChildOfClass("\087\101\108\100")if e and not v then v=(Create("\077\111\116\111\114\054\068"))({Name="\071\114\105\112";Part0=e.Part0;Part1=Handle})v.Parent=l end;(coroutine.wrap(function()if e then i=e.Part0 r=e.Part1 e.Part0=nil e.Part1=nil end end))()end local x={S.Stab}Q.Lunge:Play()S.Charge:Stop()local V=x[j:NextInteger(1,#x)]V:Play(0,nil,3)f(V.Length/3)if e then e.Part0=i e.Part1=r end if v then v:Destroy()v=nil end Tool.Enabled=true end x.OnServerEvent:Connect(function(Q,x)if Q~=B or not x or not W or W.Health<=0 or not Tool.Enabled then return end if x==Enum.KeyCode.Q then ChangeTime(l.TimetoChange)elseif x==Enum.KeyCode.E and l.LightTeleport then l.LightTeleport=false delay(5,function()l.LightTeleport=true end)t()end end)Tool.Equipped:Connect(Equipped)Tool.Unequipped:Connect(Unequipped)Tool.Activated:Connect(Activated)Tool.Deactivated:Connect(Deactivated)Services.Lighting.Changed:Connect(function(l)if l=="\067\108\111\099\107\084\105\109\101"then PassiveSpecial()end end)H(false)s(true)PassiveSpecial()


local Properties = {
	Damage = 8,
	Special = true,
	SpecialReload = 30,
	SpecialActive = false,
	TimetoChange = 12,
	LightTeleport = true
}

local Sounds = {
	Lunge = Handle:WaitForChild("Lunge"),
	Unsheath = Handle:WaitForChild("Unsheath")
}

local Remote = Tool:FindFirstChildOfClass("RemoteEvent") or Create("RemoteEvent"){
	Name = "Remote",
	Parent = Tool
}

local MousePos = Tool:FindFirstChildOfClass("RemoteFunction") or Create("RemoteFunction"){
	Name = "MouseInput",
	Parent = Tool
}

local function SunIsVisible(Character)
	local dir = Services.Lighting:GetSunDirection()
	if Vector3.new(0,1,0):Dot(dir) > 0 then
	-- BUG: particles block raycast
	local hit = workspace:FindPartOnRay(Ray.new(Handle.Position,dir*999),Character)
		if not hit or (hit and not hit.CanCollide)then
			return true
		end
	end
	return false
end

function IsInTable(Table,Value)
	for _,v in pairs(Table) do
		if v == Value then
			return true
		end
	end
	return false
end

local function Wait(para) -- bypasses the latency
	local Initial = tick()
	repeat
		Services.RunService.Stepped:Wait()
	until tick()-Initial >= para
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
	Services.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

local function EnableParticles(Verdict)
	for _,stuff in pairs(Handle:GetDescendants()) do
		if (stuff:IsA("ParticleEmitter") and stuff.Parent ~= Handle) or stuff:IsA("Light") then
			stuff.Enabled = Verdict
		end
		if stuff:IsA("Light") then
			stuff.Range = (Verdict and 10) or 3
		end
	end
end

local function SpecialParticles(Verdict)
	for _,stuff in pairs(Handle:GetDescendants()) do
		if stuff:IsA("ParticleEmitter") and stuff.Parent == Handle then
			stuff.Enabled = Verdict
		end
		if stuff:IsA("Beam") then
			stuff.TextureSpeed = (Verdict and 1) or .1
			stuff.Color = (Verdict and ColorSequence.new(Color3.new(1,1,1)) or ColorSequence.new(Color3.new(.5,.5,.5)))
		end
	end
end



local Player,Character,Humanoid,Root

function PassiveSpecial()
	--Sword of light does healing + Damage resistance when the sun is out
	--Check if Daytime then roll with ability
	--loop until time is not daytime
	if not Humanoid or Humanoid.Health <= 0 or not Character then return end
	
	if not SunIsVisible(Character) then  
		--print("Sun is not visible")
		EnableParticles(false)
		Properties.SpecialActive = false
		if Humanoid and Tool:IsDescendantOf(Character) then
			Humanoid.WalkSpeed = 16
			Properties.Damage = 14
		end
		--[[Disable particles on sword]]
		return 
	end
	
	if Humanoid and Tool:IsDescendantOf(Character) then
		Humanoid.WalkSpeed = 25
		Properties.Damage = 20
	end
	--Trigger active particles on sword
	
	if not Character:FindFirstChild(script:WaitForChild("SoLDefense").Name) and Tool:IsDescendantOf(Character) then
		local DefenseScript = script:WaitForChild("SoLDefense"):Clone()
		local ToolRef = Create("ObjectValue"){
			Name = "ToolRef",
			Value = Tool,
			Parent = DefenseScript
		}
		DefenseScript.Parent = Character
		DefenseScript.Disabled = false
	end

	
	if Properties.SpecialActive then --[[print("On Cooldown")]] return end
	--SwordMesh.VertexColor = Vector3.new(1,1,1) * 10 -- Make the sword look all bright
	
	Properties.SpecialActive = true
	EnableParticles(true)

	
end

local Animations = {}

function ChangeTime(Time) --initiate the cool time-chaning effect!
	if not Properties.Special then return end
	--warn("Changing Time")
	Properties.Special = false
	SpecialParticles(false)
	Tool.Enabled = false
	Humanoid.WalkSpeed = 0
	Animations.Summon:Play()
	delay(3,function()
		PassiveSpecial()
		Tool.Enabled = true
		Animations.Summon:Stop()
		--Humanoid.WalkSpeed = (Humanoid.WalkSpeed <=0 and 16) or Humanoid.WalkSpeed
	end)
	delay(Properties.SpecialReload,function()
		Properties.Special = true
		SpecialParticles(true)
	end)
	local TimeChange = script:WaitForChild("TimeChange"):Clone()
	local SpawnPosition = Create("Vector3Value"){
		Name = "SpawnPosition",
		Value = Root.Position - Vector3.new(0,Root.Size.Y * 1.5,0),
		Parent = TimeChange,
	}
	local Creator = Create("ObjectValue"){
		Name = "Creator",
		Value = Player,
		Parent = TimeChange
	}
	local Time = Create("NumberValue"){
		Name = "Time",
		Value = Time,
		Parent = TimeChange
	}
	TimeChange.Parent = Services.ServerScriptService
	TimeChange.Disabled = false
end

local function LightTransport()
	local LightWarpScript = script:WaitForChild("LightWarp")
	local function IsWarping()
		local stuff = Services.ServerScriptService:GetChildren()
		for i=1,#stuff do
			if stuff[i] and stuff[i].Name == LightWarpScript.Name and stuff[i]:FindFirstChild("Character") and stuff[i]:FindFirstChild("Character").Value == Character then
				return true
			end
		end
		return false
	end
	
	if IsWarping() then return end
	
	local sucess,MousePosition = pcall(function() return MousePos:InvokeClient(Player) end)
	MousePosition = (sucess and MousePosition) or Vector3.new(0,0,0)
	
	LightWarpScript = LightWarpScript:Clone()
	local CharacterTag = Create("ObjectValue"){
		Name = "Character",
		Value = Character,
		Parent = LightWarpScript
	}
	local TargetLocation = Create("Vector3Value"){
		Name = "TargetLocation",
		Value = MousePosition,
		Parent = LightWarpScript
	}
	local Range = Create("NumberValue"){
		Name = "Range",
		Value = (Properties.SpecialActive and 200) or 100,
		Parent = LightWarpScript
	}
	LightWarpScript.Parent = Services.ServerScriptService
	LightWarpScript.Disabled = false
end

local EquippedEvents = {}
local Touch



local MouseHeld = false
local CurrentMotor,RightWeld,Part0,Part1

function Equipped()
	Character = Tool.Parent
	Player = Services.Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChildOfClass("Humanoid")
	Root = Character:WaitForChild("HumanoidRootPart")
	
	if not Humanoid or Humanoid.Health <= 0 then return end
	
	Animations = Tool:WaitForChild("Animations"):WaitForChild(Humanoid.RigType.Name)
	Animations = {
		Slash = Humanoid:LoadAnimation(Animations:WaitForChild("SlashAnim")),
		Stab = Humanoid:LoadAnimation(Animations:WaitForChild("StabAnim")),
		Summon = Humanoid:LoadAnimation(Animations:WaitForChild("SummonAnim")),
		Charge = Humanoid:LoadAnimation(Animations:WaitForChild("ChargeAnim")),
	}
	Touch = Handle.Touched:Connect(function(hit)
		if not hit or not hit.Parent then return end
		local Hum,FF = hit.Parent:FindFirstChildOfClass("Humanoid"),hit.Parent:FindFirstChildOfClass("ForceField")
		if not Hum or FF or Hum.Health <= 0 or IsTeamMate(Services.Players:GetPlayerFromCharacter(Hum.Parent),Player) or Hum.Parent == Character then return end
		UntagHumanoid(Hum)
		TagHumanoid(Hum,Player)
		Hum:TakeDamage(Properties.Damage)
		print(Properties.Damage)
	end)
	PassiveSpecial()
	Sounds.Unsheath:Play()
end


function Unequipped()
	MouseHeld = false
	if Touch then Touch:Disconnect();Touch = nil end
	for AnimName,anim in pairs(Animations) do
		if anim then
			anim:Stop()
		end
	end
	if CurrentMotor then
		CurrentMotor:Destroy()
	end
	if Tool:IsDescendantOf(workspace) and not Tool:IsDescendantOf(Character) then		
		for index = 1,#EquippedEvents do
			if EquippedEvents[index] then 
				EquippedEvents[index]:Disconnect();EquippedEvents[index] = nil
			end 
		end
	end
end

local Seed = Random.new()

function Activated()
	if not Tool.Enabled or MouseHeld then return end
	MouseHeld = true	
	Animations.Charge:Play()
end

function Deactivated()
	if not Tool.Enabled or not MouseHeld then return end
	MouseHeld = false

	Tool.Enabled = false
	local RightLimb = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
	if RightLimb then
		RightWeld = RightLimb:FindFirstChildOfClass("Weld")
		if RightWeld and not CurrentMotor then
			CurrentMotor = Create'Motor6D'{
				Name = 'Grip',
				--C0 = RightWeld.C0,
				--C1 = Tool.Grip,--RightWeld.C1,
				Part0 = RightWeld.Part0,
				Part1 = Handle,
				--Parent = RightArm
			}
			CurrentMotor.Parent = RightLimb
		end
		coroutine.wrap(function()
			if RightWeld then
				Part0 = RightWeld.Part0
				Part1 = RightWeld.Part1
				RightWeld.Part0 = nil
				RightWeld.Part1 = nil
			end
		end)()
		
	end
	local AttackAnims = {--[[Animations.Slash,]]Animations.Stab}
	Sounds.Lunge:Play()
	Animations.Charge:Stop()
	local Anim = AttackAnims[Seed:NextInteger(1,#AttackAnims)]
	Anim:Play(0,nil,3);--Anim.Stopped:Wait()
	Wait(Anim.Length/3)
	if RightWeld then
		RightWeld.Part0 = Part0
		RightWeld.Part1 = Part1
	end
	if CurrentMotor then 
		CurrentMotor:Destroy();CurrentMotor = nil
	end
	Tool.Enabled = true
end


Remote.OnServerEvent:Connect(function(Client,Key)
	if Client ~= Player or not Key or not Humanoid or Humanoid.Health <= 0 or not Tool.Enabled then return end
	if Key == Enum.KeyCode.Q then
		ChangeTime(Properties.TimetoChange)
	elseif Key == Enum.KeyCode.E and Properties.LightTeleport then
		Properties.LightTeleport = false
		delay(5,function()
			Properties.LightTeleport = true
		end)
	 	LightTransport()
	end
end)

Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)
Tool.Activated:Connect(Activated)
Tool.Deactivated:Connect(Deactivated)

Services.Lighting.Changed:Connect(function(property)
	if property == "ClockTime" then
		PassiveSpecial()
	end
end)
EnableParticles(false)
SpecialParticles(true)
PassiveSpecial()--trigger it initially on start
