--Rescripted by Luckymaxer



Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

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

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

black= BrickColor.new("Really black")

BaseUrl = "http://www.roblox.com/asset/?id="
LastAttack = 0
Lunging = false

Grips = {
	Up = CFrame.new(0, -2.3, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),
	Out = CFrame.new(0, -2.3, 0, 1, 0, 0, 0, 0, -1, -0, 1, 0),
}

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

BasePart = Create("Part"){
	Material = Enum.Material.Plastic,
	Shape = Enum.PartType.Block,
	TopSurface = Enum.SurfaceType.Smooth,
	BottomSurface = Enum.SurfaceType.Smooth,
	FormFactor = Enum.FormFactor.Custom,
	Size = Vector3.new(0.2, 0.2, 0.2),
	CanCollide = true,
	Locked = true,
}

SoulFire = Create("Fire"){
	Name = "Fire",
	Color = Color3.new((255 / 255), (0 / 255), (0 / 255)),
	SecondaryColor = Color3.new((85 / 255), (0 / 255), (0 / 255)),
	Heat = 18,
	Size = 2.5,
	Enabled = true,
}
SoulLight = Create("PointLight"){
	Name = "Light",
	Color = SoulFire.Color,
	Brightness = 35,
	Range = 4,
	Shadows = false,
	Enabled = true,
}

Gravity = 196.20

SwordDamage = 25

ToolEquipped = false

ServerControl = (Tool:FindFirstChild("ServerControl") or Create("RemoteFunction"){
	Name = "ServerControl",
	Parent = Tool,
})

ClientControl = (Tool:FindFirstChild("ClientControl") or Create("RemoteFunction"){
	Name = "ClientControl",
	Parent = Tool,
})

Tool.Grip = Grips.Up
Tool.Enabled = true

function IsTeamMate(Player1, Player2)
	local myteam = Player1.TeamColor
	local theirteam = Player2.TeamColor
	return not (myteam ~= theirteam or (myteam == black and theirteam == black))
end

function TagHumanoid(humanoid, player)
	local Creator_Tag = Create("ObjectValue"){
		Name = "creator",
		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 Blow(Part, Damage)
	local PartTouched
	PartTouched = Part.Touched:connect(function(Hit)
		if not Hit or not Hit.Parent or not CheckIfAlive() then
			return
		end
		local RightArm = Character:FindFirstChild("Right Arm")
		if not RightArm then
			return
		end
		local RightGrip = RightArm:FindFirstChild("RightGrip")
		if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
			return
		end
		local character = Hit.Parent
		if character == Character then
			return
		end
		local humanoid = character:FindFirstChild("Humanoid")
		if not humanoid or humanoid.Health == 0 then
			return
		end
		local player = Players:GetPlayerFromCharacter(character)
		if player and (player == Player or IsTeamMate(Player, player)) then
			return
		end
		local HealthAfter = (humanoid.Health - Damage)
		UntagHumanoid(humanoid)
		TagHumanoid(humanoid, Player)
		humanoid:TakeDamage(Damage)
		Spawn(function()
			humanoid.WalkSpeed = 9
			wait(1.25)
			humanoid.WalkSpeed = 16
		end)
	end)
	return PartTouched
end

function CreateTrail(Damage, TrailRate)
	local TrailLoop
	local Count = Create("IntValue"){
		Value = 0,
	}
	local Enabled = Create("BoolValue"){
		Value = true,
	}
	Spawn(function()
		while Enabled.Value and ToolEquipped and CheckIfAlive() do
			local TrailPart = Handle:Clone()
			TrailPart.Name = "Effect"
			TrailPart.CanCollide = false
			TrailPart.Anchored = true
			Blow(TrailPart, 5)
			Count.Value = (Count.Value + 1)
			Debris:AddItem(TrailPart, 1)
			TrailPart.Parent = game:GetService("Workspace")
			TrailPart.CFrame = Handle.CFrame
			wait(TrailRate)
		end
	end)
	return {Connection = TrailLoop, Count = Count, Enabled = Enabled}
end

function Lunge()
	Lunging = true
	local Target = InvokeClient("MousePosition")
	if not Target then
		return
	end
	local TargetPosition = Target.Position
	local Direction = (CFrame.new(Torso.Position, TargetPosition).lookVector * Vector3.new(1, 0, 1))
	Tool.Grip = Grips.Out
	Sounds.Lunge:Play()
	local Anim = Create("StringValue"){
		Name = "toolanim",
		Value = "Lunge",
		Parent = Tool,
	}
	if Direction.Magnitude > .01 then
		Direction = Direction.Unit 
		local NewBV = Create("BodyVelocity"){
			P = 100000,
			maxForce = Vector3.new(100000, 0, 100000),
			velocity = (Direction * 50),
		}
		Debris:AddItem(NewBV, 0.75)
		NewBV.Parent = Torso
		Torso.CFrame = CFrame.new(Torso.Position, (TargetPosition * Vector3.new(1, 0, 1) + Vector3.new(0, Torso.Position.Y, 0)))
	end
	Spawn(function()
		local LungeTrail = CreateTrail(5, 0.08)
		while Lunging and CheckIfAlive() and ToolEquipped do
			RunService.Stepped:wait()
		end
		LungeTrail.Enabled.Value = false
	end)
	wait(0.75)
	Lunging = false 
	Tool.Grip = Grips.Up
	wait(0.5)
end

function Attack()		
	Tool.Grip = Grips.Up
	Sounds.Slash:Play()
	local Anim = Create("StringValue"){
		Name = "toolanim",
		Value = "Slash",
		Parent = Tool,
	}
	Spawn(function()
		local AttackTrail = CreateTrail(5, 0.06)
		while AttackTrail.Count.Value < 4 and CheckIfAlive() and ToolEquipped do
			RunService.Stepped:wait()
		end
		AttackTrail.Enabled.Value = false
	end)
	Tool.Grip = Grips.Up
end