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