TextButton not firing code when clicked?

I’m trying to make a textbutton that, when clicked, makes some UI invisible and changes a boolValue’s value. The problem is, the code isn’t firing. The script is a Local Script under the textbutton.

My code:

local HoverSound = script.Parent.HoverSound
local plrGui = game.Players.LocalPlayer.PlayerGui
local Setup = plrGui.SetupWeapons
local deploybutton = plrGui:WaitForChild('DeployGui'):WaitForChild('DeployFrame'):WaitForChild('Deploy')

script.Parent.MouseEnter:Connect(function()
	HoverSound:Play()
	print('playerd')
end)

deploybutton.MouseButton1Click:Connect(function()
	print('ok')
	Setup.Value = true
	plrGui:WaitForChild('DeployGui').DeployFrame.Visible = false
	plrGui:WaitForChild('DeployGui').ScrollingFrame.Visible = false
	plrGui:WaitForChild('DeployGui').ChooseClass.Visible = false
	plrGui:WaitForChild('DeployGui').SecondariesScrollingFrame.Visible = false
	plrGui:WaitForChild('DeployGui').Modal.Visible = false
	plrGui:WaitForChild('DeployGui').TextLabel.Visible = false
	print('all done')
end)

The print command

print('ok')

isn’t firing either.

i dont see the point why u didnt put the local script in the plr gui to access it easier
u can put the Sound in the script

Can you just answer the question please? The sound is in the script. I put the script in the textbutton because the script is meant to do something when the button is clicked, but it’s not.

I believe the first thing you could try to do is instead of getting the playergui via game.Players.LocalPlayer, you use use .Parent as many times needed to go back to StarterGui, which when testing, will be PlayerGui for the script

What’s the hierachy of the StarterGui from the button?

Try this

local HoverSound = script.Parent.HoverSound
local plrGui = script.Parent.Parent.Parent.Parent --StarterGui
local Setup = plrGui.SetupWeapons
local deploybutton = script.Parent
local deploygui = script.Parent.Parent.Parent

script.Parent.MouseEnter:Connect(function()
	HoverSound:Play()
	print('playerd')
end)

deploybutton.MouseButton1Click:Connect(function()
	print('ok')
	Setup.Value = true
	for i,v in pairs(deploygui:GetChildren()) do
		if not v:IsA("Folder") then
			v.Visible = false
		end
	end
	print('all done')
end)

I also included a little way to make the thing you wanted to do when the button is clicked a bit more simpler to do

I managed to fix it, the ZIndex of the button was below another button, putting the ZIndex of the button that needed to be fired to around 15 made it work

Glad to see you’ve fixed it! If you have anymore issues don’t be afraid to make another post!

1 Like

actually its not recomended to set everything visible to false instead you can just disable the ScreenGUI

    Setup.Value = true
	script.Parent.Parent.Parent.Enabled = false

Oh right, I must’ve zoned out when figuring out a way to make the code much more easier whilst also trying to think of a solution for OP and didn’t realise that what he did is the same as disabling the gui, thanks!

1 Like