You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Clicking buttons
-
What is the issue? Only allows me to click 2, if I try click additional buttons nothing happens
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local TopBar = {}
local players = game:GetService('Players')
local player = players.LocalPlayer
local playergui = player.PlayerGui
local function buttons_(buttonName)
local frames = playergui:WaitForChild('MainUI'):WaitForChild('Frames')
for _, child in pairs(frames:GetChildren()) do
if child:IsA("GuiObject") then
child.Visible = false
end
end
if buttonName == 'profile' then
frames:WaitForChild('ProfileHolder').Visible = true
print('profile')
elseif buttonName == 'currency' then
frames:WaitForChild('ConversionHolder').Visible = true
print('currency')
elseif buttonName == 'settings' then
frames:WaitForChild('SettingsHolder').Visible = true
print('settings')
elseif buttonName == 'upgrades' then
frames:WaitForChild('UpgradesHolder').Visible = true
print('upgrades')
else
return
end
end
function TopBar.init(MainFrame)
print('init')
local ButtonsFolder = MainFrame:WaitForChild('Others')
local HolderFrame = ButtonsFolder:WaitForChild('Holder')
local MainHolder = HolderFrame:WaitForChild('Main') -- holds all the buttons
local buttons = { -- all the buttons
profile = MainHolder:WaitForChild('Profile'),
currency = MainHolder:WaitForChild('Currency'),
settings = MainHolder:WaitForChild('Settings'),
upgrades = MainHolder:WaitForChild('Upgrades')
}
local hoverTemplate = script:FindFirstChild('Hover')
local clickTemplate = script:FindFirstChild('Click')
if not hoverTemplate or not clickTemplate then
warn("Hover or Click sound missing in script!")
return
end
for n, butn in pairs(buttons) do -- n = name
butn.MouseEnter:Connect(function()
pcall(function()
local hoverSFX = hoverTemplate:Clone()
hoverSFX.Name = 'hover'
hoverSFX.Parent = butn
hoverSFX:Play()
end)
end)
butn.MouseLeave:Connect(function()
if butn:FindFirstChild('hover') then
butn:FindFirstChild('hover'):Stop()
butn:FindFirstChild('hover'):Destroy()
elseif butn:FindFirstChild('p') then
butn:FindFirstChild('p'):Stop()
butn:FindFirstChild('p'):Destroy()
end
end)
butn.MouseButton1Click:Connect(function()
pcall(function()
local purchaseSFX = clickTemplate:Clone()
purchaseSFX.Name = 'p'
purchaseSFX.Parent = butn
purchaseSFX:Play()
game.Debris:AddItem(purchaseSFX, 2)
end)
buttons_(n)
end)
end
end
return TopBar
heres the local script
local Players = game:GetService('Players')
local TS = game:GetService('TweenService')
local RS = game:GetService('ReplicatedStorage')
local Modules = RS:WaitForChild('Modules')
local UIFolder = Modules:WaitForChild('UI')
local TopBarModule = require(UIFolder:WaitForChild('TopBarModule'))
local mainFrame = script.Parent
TopBarModule.init(mainFrame)