Buttons not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Clicking buttons

  2. 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)
local function buttons_(buttonName)

Print buttonName to make sure it goes through the function.

Possible could be because of the pcall added inside the MouseButton1Click function which will yield if error found. Remove the pcall!

Is that a sort of unfunny joke/ragebait?
Im dead serious by the way.

1 Like

i added it cause i was trying to see what the issue was, relax

ive removed the pcall, it definetly isnt that causing the issue, ive printed buttonName and everything is correct

It does the opposite-
No errors and no linting = goodluck finding the problem.

ok i wont do that if this happens again :folded_hands: