--Added those two (if player/if not player) in so this wouldn't break if you used it on AI, or something of the sort. 



	end
end


function tagHumanoid(humanoid, player)
	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = humanoid
end

function untagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end


function attack()
	damage = slash_damage
	SlashSound:play()
	local anim = Instance.new("StringValue")
	anim.Name = "toolanim"
	anim.Value = "Slash"
	anim.Parent = Tool
end
local fx=script.Parent:FindFirstChild("Blade")
local fx2=script.Parent.Blade:FindFirstChild("Stroke")

function lunge()
	damage = lunge_damage

	LungeSound:play()

	local anim = Instance.new("StringValue")
	anim.Name = "toolanim"
	anim.Value = "Lunge"
	anim.Parent = Tool
	
	
	local force = Instance.new("BodyVelocity")
	force.velocity = Vector3.new(0,10,0) 
	force.maxForce = Vector3.new(0,4000,0) -- ADD THIS TO CHANGE MOMENTUM
	force.Parent = Tool.Parent.Torso
	if fx and fx2 and fxToggled then fx2.Enabled=true end
	wait(.25)
	swordOut()
	wait(.25)
	force.Parent = nil
	wait(.5)
	swordUp()
	if fx and fx2 then fx2.Enabled=false end

	damage = slash_damage
end

function swordUp()
	Tool.GripForward = Vector3.new(1, 0, 0)
	Tool.GripRight = Vector3.new(0, 0, -1)
	Tool.GripUp = Vector3.new(0, -1, 0)
end

function swordOut()
	Tool.GripForward = Vector3.new(1, 0, 0)
	Tool.GripRight = Vector3.new(0, 0, -1)
	Tool.GripUp = Vector3.new(-20, -1, 0)
end

function swordAcross()
	-- parry
end


Tool.Enabled = true
local last_attack = 0
function onActivated()

	if not Tool.Enabled then
		return
	end

	Tool.Enabled = false

	local character = Tool.Parent;
	local humanoid = character.Humanoid
	if humanoid == nil then
		print("Humanoid not found")
		return 
	end

	local t = r.Stepped:wait()

	if (t - last_attack < .2) then
		lunge()
	else
		attack()
	end

	last_attack = t

	--wait(.5)

	Tool.Enabled = true
end


function onEquipped()
	UnsheathSound:play()
end
script.Parent.Effects.OnServerEvent:connect(function(p,toggle)
	local ch=script.Parent.Blade:GetChildren()
	for i=1,#ch do 
		if ch[i].ClassName=="ParticleEmitter" or ch[i].ClassName=="PointLight" then
			ch[i].Enabled=toggle
		end
	end
	spawn(function()
		wait(.5)
		script.Parent.Blade.Stroke.Enabled=false
	end)
	fxToggled=toggle
	if not toggle then
		script.Parent.Blade.Material=Enum.Material.Metal
		script.Parent.Blade.BrickColor=BrickColor.new("Institutional white")
		damage=5
		slash_damage=10
		lunge_damage=30

	else
		script.Parent.Blade.Material=Enum.Material.Neon
		script.Parent.Blade.BrickColor=BrickColor.new("Cool yellow")
		damage=15
		slash_damage=20
		lunge_damage=50
	end
end)

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)


connection = sword.Touched:connect(blow)


