Is there a better more compact way of handling tooltips?

All these MouseEnter and MouseLeave connections handle animations for text which displays the title/purpose of the “bar”.

Is there an alternative way of handling many connections without having to do this?

local BarTweenInfo = TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

Bar_Health.Parent.Hover.MouseEnter:Connect(function()
	t:Create(Bar_Health.Parent.HealthTitle,BarTweenInfo, {TextTransparency = 0}):Play()
end)

Bar_Health.Parent.Hover.MouseLeave:Connect(function()
	t:Create(Bar_Health.Parent.HealthTitle,BarTweenInfo, {TextTransparency = 1}):Play()
end)

Bar_Hunger.Parent.Hover.MouseEnter:Connect(function()
	t:Create(Bar_Hunger.Parent.HungerTitle,BarTweenInfo, {TextTransparency = 0}):Play()
end)

Bar_Hunger.Parent.Hover.MouseLeave:Connect(function()
	t:Create(Bar_Hunger.Parent.HungerTitle,BarTweenInfo, {TextTransparency = 1}):Play()
end)

Bar_Thirst.Parent.Hover.MouseEnter:Connect(function()
	t:Create(Bar_Thirst.Parent.ThirstTitle,BarTweenInfo, {TextTransparency = 0}):Play()
end)

Bar_Thirst.Parent.Hover.MouseLeave:Connect(function()
	t:Create(Bar_Thirst.Parent.ThirstTitle,BarTweenInfo, {TextTransparency = 1}):Play()
end)

breathBar.Parent.Hover.MouseEnter:Connect(function()
	t:Create(breathBar.Parent.OxygenTitle,BarTweenInfo, {TextTransparency = 0}):Play()
end)

breathBar.Parent.Hover.MouseLeave:Connect(function()
	t:Create(breathBar.Parent.OxygenTitle,BarTweenInfo, {TextTransparency = 1}):Play()
end)

staminaBar.Parent.Hover.MouseEnter:Connect(function()
	t:Create(staminaBar.Parent.StaminaTitle,BarTweenInfo, {TextTransparency = 0}):Play()
end)

staminaBar.Parent.Hover.MouseLeave:Connect(function()
	t:Create(staminaBar.Parent.StaminaTitle,BarTweenInfo, {TextTransparency = 1}):Play()
end)
2 Likes

Use code automation. Instead of setting everything up yourself make a for loop do it.

Example: let’s say that we have a Gui with a lot of buttons - like 200 - that for some reason do the same thing. Applying the same function for the same event for each button is just not a thing to do, instead using a for loop is way better because saves you time and script’s length.

for i, button in pairs(gui:GetChildren()) do
   button.MouseButton1Click:Connect(function() 
       print("Button clicked.")
   end)
end
6 Likes