--AdditionPerIntelligence: Increase to heal power per Intelligence.
--BaseHeal: How much it will heal before any attribute modifiers.
--Cooldown: How long you have to wait before you can cast again.
--ManaCost: The amount of MP needs to cast.
--Offset: The offset to heal amount. (Example: If set to 2, it will randomly add or subtract anything from -2 to +2.)


Tool = script.Parent

Debris = Game:GetService("Debris")

script.Parent.ToolTip = "Cost: " .. script.Parent.PROPERTIES.ManaCost.Value .. " MP"

function Heal()
	Character = Tool.Parent
	Player = Game.Players:GetPlayerFromCharacter(Character)
	if script.Parent.Enabled == true and Player ~= nil then
		if Player.Stats.Mana.Value >= script.Parent.PROPERTIES.ManaCost.Value then
			script.Parent.Enabled = false
			HealAmount = script.Parent.PROPERTIES.BaseHeal.Value + (script.Parent.PROPERTIES.AdditionPerIntelligence.Value * Player.attributes.Intelligence.Value) + math.random(-script.Parent.PROPERTIES.Offset.Value, script.Parent.PROPERTIES.Offset.Value)
			
			--Heal text
			local part = Instance.new("BillboardGui")
			part.Size = UDim2.new(0,50,0,100) 
			part.StudsOffset = Vector3.new(0,2,0)
			local part2 = Instance.new("TextLabel") 
			dt = Game.ReplicatedStorage.DynamicText:Clone()
			part2.Font = "SourceSansBold"
			part2.FontSize = "Size24"
			part2.TextStrokeTransparency = 0
			part2.Size = UDim2.new(1,0,1,0) 
			part2.Position = UDim2.new(0,0,0,0) 
			part2.BackgroundTransparency = 1
			part2.Parent = part 
			part2.TextColor3 = Color3.new(0, 1, 0)
			dt.Parent = part2
			dt.Disabled = false
			part.Parent = Character.Head
			part.Adornee = part.Parent
			
			part2.Text = "+" .. HealAmount
			Debris:AddItem(part, 2)		
			
			Character.Humanoid.Health = Character.Humanoid.Health + HealAmount
			Player.Stats.Mana.Value = Player.Stats.Mana.Value - script.Parent.PROPERTIES.ManaCost.Value
			wait(script.Parent.PROPERTIES.Cooldown.Value)
			script.Parent.Enabled = true
		else print("Insufficient mana!")
		end
	else print("Either cooldown is in effect or player doesn't exist!")
	end	
end

script.Parent.Activated:connect(Heal)
