CCCPaste

New ToolScript With QuantityText (UPDATE)

local Tool = script.Parent

local player = game.Players.LocalPlayer
local QuantityText = player.PlayerGui:WaitForChild("BackpackGui").Frame.Quantity
local Enabled = true

Tool:WaitForChild("stacks").Changed:Connect(function(value)
	QuantityText.Text = "Quantity: "..value
end)

QuantityText.Text = "Quantity: "..Tool.stacks.Value

Tool.Activated:Connect(function()
	if not Enabled then
		return
	end
	
	Enabled = false
	
	Tool.GripForward = Vector3.new(-0.976,0,-0.217)
	Tool.GripPos = Vector3.new(.95,-0.76,1.4)
	Tool.GripRight = Vector3.new(0.217,0, 0.976)
	Tool.GripUp = Vector3.new(0,1,0)

	wait(.8)

	local Humanoid = player.Character:FindFirstChild("Humanoid")
	if (Humanoid ~= nil) then
		if (Humanoid.MaxHealth > Humanoid.Health + 1.6) then
			Humanoid.Health = Humanoid.Health + 1.6
		else    
			if Humanoid.Health == Humanoid.MaxHealth then
				if Tool:WaitForChild("stacks") and Tool.stacks.Value > 1 then
					Tool.stacks.Value = Tool.stacks.Value - 1
				else
					Tool:Destroy()
                    QuantityText.Visible = false
				end
			end
		end
	end

	Tool.GripForward = Vector3.new(-0.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.3,0,0)
	Tool.GripRight = Vector3.new(0.217,0,-0.976)
	Tool.GripUp = Vector3.new(0,1,0)

	Enabled = true
end)

Tool.Equipped:Connect(function()
	QuantityText.Visible = true
    QuantityText.Text = "Quantity: "..Tool.stacks.Value
end)

Tool.Unequipped:Connect(function()
	QuantityText.Visible = false
end)