Image not becoming invisible and

Hello!

While adding a shop ui and scripting the buttons. I have come to a problem where when I click the button the image that was supposed to appear didn’t. I have added prints to the script and found at that the function didn’t work. Any solutions?

Script:

local winButton = script.Parent
local shopWins = winButton.Parent
local shopGUI = shopWins.Parent
local shopDonate = shopGUI:FindFirstChild("ShopDonate")
print("variables")

if shopDonate then
	-- Click Sound
	local Click = Instance.new("Sound")
	Click.Parent = winButton
	Click.SoundId = "rbxassetid://876939830"
	print("Click")

	local function onWinButtonClicked() -- function not working
		print("function") 
		if shopDonate.Visible then
			print("SDV true")
			shopDonate.Visible = false
			shopWins.Visible = true
		else
			shopDonate.Visible = true
			shopWins.Visible = false
		end

		-- Play the click sound
		Click:Play()
	end

	winButton.MouseButton1Click:Connect(onWinButtonClicked)
else
	warn("ShopDonate not found in ShopGUI")
end

Is it in a local script or a server script?

this script is a local script located inside the button

Is the Active Property enabled for the button

Yes active and interactible properties are set to true

The mousebutton1click event works fine for me, is print(“function”) printing inside the event or not?

The print(“function”) is printing inside the function

Then it has something to do with shopdonate probably.

Is it actually visible when you’re clicking the button?

No it is not viable when i click the button

Make sure the win button is a TextButton or an ImageButton and not a TextLabel or a TextBox or an ImageLabel.

It is a text button not a text label

Maybe the problem is in the “if shopDonate.Visible then” maybe try “if shopDonate.Visible == true then” and does the script that closes the shopWins work?

Nope that does still dosn’t work

1 Like

Does the script close shopWins if it’s open?

The local scripts is located in workspace? (Wrong reply)

Hopefully making some changes to the script will fix the issue:

local winButton = script.Parent
local shopWins = winButton.Parent

local shopGUI = shopWins.Parent
local shopDonate = shopGUI:WaitForChild("ShopDonate")

local click = Instance.new("Sound")
click.SoundId = "rbxassetid://876939830"
click.Parent = winButton

local function onWinButtonClicked()
	print("Click detected")

	if shopDonate.Visible then
		shopDonate.Visible = false
		print("ShopDonate is now invisible")

		shopWins.Visible = true
	else
		shopDonate.Visible = true
		print("ShopDonate is now visible")

		shopWins.Visible = false
	end

	click:Play()
end

winButton.MouseButton1Click:Connect(onWinButtonClicked)

Uh i am not quite sure what you mean by that. In my script I have basicly an image that is visable and win I press a tab i want that image to be invisible and another image to be visible. When the button is clicked the image does not become invisible and the image does not become visible

It is located in the wins button

Nope unfortunately that script does not work