local currentTab = 1
local function setUpText()
local buildingData = (currentTab == 1) and module.barracks or module.uttility
for i = 1, 4 do
local button = buildingFrame1:FindFirstChild("Building" .. i)
if button and button:IsA("ImageButton") then
local buildingName = button:FindFirstChild("BuildingName")
local building = buildingData["Building" .. i]
if building then
buildingName.Text = building.Name
button.MouseEnter:Connect(function()
buildingName.Text = "$" .. building.Price
end)
button.MouseLeave:Connect(function()
buildingName.Text = building.Name
end)
else
buildingName.Text = "No Building"
end
end
end
end
this is the code that changes tabs:
local function switchTab(tabNumber)
currentTab = tabNumber
setUpText() -- Update button texts when tab changes
end
frame.Tab1Button.MouseButton1Click:Connect(function()
switchTab(1)
end)
frame.Tab2Button.MouseButton1Click:Connect(function()
switchTab(2)
end)
So when I change tabs the text does display the right names for each button, the thing is when I am on tab 1 and hover an button it will get the button number and go inside the module to get all the info for the correspondant number
example
["Building1"] = {
Name = "Normal Barrack",
Price = 50,
model = buildingsFolder.Barracks.NormalBarrack
};
Tho once I hover off the button it should go back to showing the name instead of the price. Tho if I press on Tab 1 it works fine, once I go into tab 2, it displays the text on click but once I hover off it shows the tab 1 names