Only 2 buttons working

I have been trying to figure out why it won’t let me click more than 2 buttons. When I click 2 it works fine but if I click another 2 or the same ones again NOTHING happens. It is really starting to annoy me as I have been working on it since last night and I really just don’t understand the issue. Please help me.

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
	end
	if buttonName == 'currency' then
		frames:WaitForChild('ConversionHolder').Visible = true
	end
	if buttonName == 'settings' then
		frames:WaitForChild('SettingsHolder').Visible = true
	end
	if buttonName == 'upgrades' then
		frames:WaitForChild('UpgradesHolder').Visible = true
	end
end

function TopBar.init(MainFrame)
	print('init')
	local ButtonsFolder = MainFrame:WaitForChild('Others')
	local HolderFrame = ButtonsFolder:WaitForChild('Holder')
	local MainHolder = HolderFrame:WaitForChild('Main')

	local 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
		return
	end

	for n, butn in pairs(buttons) do
		butn.MouseEnter:Connect(function()
			local hoverSFX = hoverTemplate:Clone()
			hoverSFX.Name = 'hover'
			hoverSFX.Parent = butn
			hoverSFX:Play()
		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()
			local purchaseSFX = clickTemplate:Clone()
			purchaseSFX.Name = 'p'
			purchaseSFX.Parent = game:GetService("SoundService")
			purchaseSFX:Play()
			game.Debris:AddItem(purchaseSFX, 2)
			buttons_(n)
		end)
	end
end

return TopBar

-- 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)


Thank you

2 Likes

Maybe need a debounce for your MouseButton1Click function ?

In your table loop for the buttons, it looks like in the second function MouseLeave you destroy p, but directly below it on MouseButton1Click you create it via a clone ? Is this where an issue could be happening ?

What exactly is not working ? I’ve duplicated this on my end and the buttons click and ding properly.

nah, thats a different sound effect, theres a hover sfx and a click sfx

ill try add a debounce for it now

ive tried adding a debounce, still not working, ive tried printing when u click any of the buttons and for some reason if i click 2 it prints but if i click 2 more or the same ones it just doesnt print anything after, i really dont know why

Are you hearing all of your sounds ? Or is your issue that it is not printing the print statement each time ?
The print statement is not inside the MouseEnter or MoutLeave or MouseButton1Click functions so its not going to print again. All four of my buttons are making both sounds. So it appears to be working. If it is not working for you, that suggests to me that another script or your setup might be interfering. I threw something together pretty quickly in my Studio and mine is working though on sound. I did not however set up all the other FRAMES and maybe I mis -understood you, that this is the part that isn’t doing something for you.

Where does the Frames sit in your GUI window ? Your script shows it as being a child of MainGUI. What is inside those Frames ?

Here is my setup screen image: Everything is becoming Visible when the button is clicked and my print statements are as well.

The issue was there was a frame covering it. Fixed now!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.