-------- OMG HAX


r = game:service("RunService")


local damage = 0

local slash_damage = 0

local debounce = false
function blow(hit)
	local humanoid = hit.Parent:findFirstChild("Immortal")
	local vCharacter = script.Parent.Parent
	local vPlayer = game.Players:playerFromCharacter(vCharacter)
	local hum = vCharacter:findFirstChild("Immortal") -- non-nil if tool held by a character
	if humanoid~=nil and humanoid ~= hum and hum ~= nil then
	-- final check, make sure sword is in-hand
		if debounce == false then				
			debounce = true
			tagHumanoid(humanoid, vPlayer)
			zomghit = 0 + script.Parent.AddDam.Value
			humanoid:TakeDamage(zomghit)
			untagHumanoid(humanoid)
			wait(0.35)
			debounce = false	
		end
	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
	
	local Slash1 = script.Parent.Handle.Slash1

	local Slash2 = script.Parent.Handle.Slash2

	Slashsounds={Slash1, Slash2}
	
	Whoosh=(Slashsounds[math.random(1,#Slashsounds)])
	Whoosh:play()
	local vCharacter = script.Parent.Parent
	local hum = vCharacter:findFirstChild("Immortal")
	
	Move1 = hum:LoadAnimation(script.Parent.Handle.LeftSlash)
	Move2 = hum:LoadAnimation(script.Parent.Handle.OverHeadSwing)
	Move3 = hum:LoadAnimation(script.Parent.Handle.RightSlash)

	
	MovesLikeJagger={Move1, Move2, Move3}
	IGotThem=(MovesLikeJagger[math.random(1,#MovesLikeJagger)])
	IGotThem:Play()
	--hum.WalkSpeed = 0
	wait(.1)
	Whoosh:play()
	wait(.1)
	--hum.WalkSpeed = 16
end

script.Parent.Enabled = true

function onActivated()

	if not script.Parent.Enabled then
		return
	end

	script.Parent.Enabled = false

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

	attack()

	wait(.1)

	script.Parent.Enabled = true
end


function onEquipped()
	--if Tool.Handle.LightsaberOn.isPlaying == false then
		script.Parent.Handle.LightsaberOn:play()
		script.Parent.Handle.IdleLoop:Play()	
	--end
end

function onUnequipped()

	script.Parent.Handle.LightsaberOff:stop()
	script.Parent.Handle.IdleLoop:Stop()
end

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

connection = script.Parent.Handle.Touched:connect(blow)


