-- Copied from Grimgold Periastron Beta


local Tool = script.Parent
local Sword = Tool.Handle

local vCharacter
local myTorso
local myHumanoid 

local equipped = false

local debris = game:GetService("Debris")

function tagHumanoid(humanoid, player)
	if humanoid then 
		local creatorTag = Instance.new("ObjectValue")
		creatorTag.Value = player
		creatorTag.Name = "creator"
		creatorTag.Parent = humanoid
		debris:AddItem(creatorTag, 1)
	end
end

function cut(hit)
	local humanoid
	local vPlayer
	if hit and hit.Parent and myHumanoid then 
		if hit.Parent.className == "Hat" then
			humanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
		else
			humanoid = hit.Parent:FindFirstChild("Humanoid")
		end
		vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)
		if humanoid ~= nil and humanoid ~= myHumanoid then 
			tagHumanoid(humanoid, vPlayer)
			humanoid:TakeDamage(7.)
		end
	end
end

function onEquipped()
	vCharacter = Tool.Parent
	myTorso = vCharacter:FindFirstChild("Torso")
	myHumanoid = vCharacter:FindFirstChild("Humanoid")	
end

Tool.Equipped:connect(onEquipped)

Sword.Touched:connect(cut)
