UI Scripting Help

local MarketplaceService = game:GetService("MarketplaceService")

local tst1 = script.Parent.Parent.Test1
local tst2 = script.Parent.Parent.test2
local tst3 = script.Parent.Parent.test3
local txtbutton = script.Parent.Parent.CloseShop
local MainFrame = script.Parent
local VipGamepass = MainFrame.VipGamepassFrame.Buy
local ColorChangeNameGamepass = MainFrame.ColorChangeGamepassFrame.Buy3
local JetskiGamepass = MainFrame.JetskiGamepassFrame.Buy5
local PetFishGamepass = MainFrame.PetFishTrailGamepassFrame.Buy6
local RedTrailGamepass = MainFrame.RedTrailGamepassFrame.Buy8
local SubmarineGamepass = MainFrame.SubmarineGamepassFrame.Buy9
local SurfboardGamepass = MainFrame.SurfboardsGamepassFrame.Buy10
local OpenShop = MainFrame.Parent.OpenShop

local player = game.Players.LocalPlayer

local VipGamepassId = 4811928
local ColorChangeNameGamepassId = 5283084
local JetskiGamepassId = 4934981
local PetFishGamepassId = 5312626
local RedTrailGamepassId = 5182395
local SubmarineGamepassId = 6212971
local SurfboardGamepassId = 5242168



VipGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, VipGamepassId)	
end)
	
	if hasPass == true then
		print("Player has pass")
		else
			MarketplaceService:PromptGamePassPurchase(player, VipGamepassId)
		end
	end)

	ColorChangeNameGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, ColorChangeNameGamepassId)	
end)
	
	if hasPass == true then
		print("Player has pass")
		else
			MarketplaceService:PromptGamePassPurchase(player, ColorChangeNameGamepassId)
		end
	end)

	JetskiGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, JetskiGamepassId)	
end)
	
	if hasPass == true then
		print("Player has pass")
		else
			MarketplaceService:PromptGamePassPurchase(player, JetskiGamepassId)
		end
	end)
	PetFishGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, PetFishGamepassId)	
end)
	
	if hasPass == true then
		print("Player has pass")
		else
			MarketplaceService:PromptGamePassPurchase(player, PetFishGamepassId)
		end
	end)
	
	RedTrailGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, RedTrailGamepassId)	
end)
	
	if hasPass == true then
		print("Player has pass")
		else
			MarketplaceService:PromptGamePassPurchase(player, RedTrailGamepassId)
		end
	end)
	SubmarineGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, SubmarineGamepassId)	
end)
	
	if hasPass == true then
		print("Player has pass")
		else
			MarketplaceService:PromptGamePassPurchase(player, SubmarineGamepassId)
		end
	end)
	SurfboardGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, SurfboardGamepassId)	
end)
	
	if hasPass == true then
		print("Player has pass")
		else
			MarketplaceService:PromptGamePassPurchase(player, SurfboardGamepassId)
		end
	end)
		
txtbutton.Visible = false
MainFrame.Visible = false
	tst1.Visible = false
	tst2.Visible = false
	tst3.Visible = false

OpenShop.MouseButton1Down:Connect(function()
	MainFrame.Visible = not MainFrame.Visible
	txtbutton.Visible = not txtbutton.Visible
	tst1.Visible = not tst1.Visible
	tst2.Visible = not tst1.Visible
	tst3.Visible = not tst1.Visible
end)

The issue in the code above is below.
https://gyazo.com/ed429f7205733031872a35d2e4bc8be0

CloseButton:

local MainFrame = script.Parent.Parent
local CloseShop = MainFrame.CloseShop

CloseShop.MouseButton1Down:Connect(function()
	MainFrame.Visible = false
end)

Issue: Visible is not a valid member of ScreenGui

How my screen gui is: https://gyazo.com/dea5120a52d77cf89700d5d8910b34ee

Thank you for your help!

1 Like

try:

script.Parent

(30 Characters)

2 Likes

Nope, Error: CloseShop is not a valid member of TextButton

I think its correct, but ScreenGui’s don’t have a visible property, but they have an Enabled property.

1 Like

I’ve notice that the CloseShop is not inside of the MainFrame,

So try this:

local MainFrame = script.Parent
local CloseShop = script.Parent.Parent.CloseShop

CloseShop.MouseButton1Down:Connect(function()
	MainFrame.Visible = false
end)

What do you mean? I showed everything there.

In LocalScripts, you should use WaitForChild() instead of directly indexing the object, since it takes time for objects to replicate from the server to the client.

1 Like

That closes the button itself not the actual gui.

https://gyazo.com/9a9c4da421d5a88b856dcf2d493f3a52

1 Like

The code worked when I didn’t use a scroll frame, but I am trying to update it and use a scroll frame. The issue I am having is the three test images, are not appearing and disappearing with the main frame.

1 Like

You should still try using WaitForChild() regardless, since replication time is pretty inconsistent.

1 Like

You should open the closebutton so that I didn’t confuse. :smiley:
Fixed now:

local MainFrame = script.Parent.Parent:WaitForChild("MainFrame")
local CloseShop = script.Parent

CloseShop.MouseButton1Down:Connect(function()
	MainFrame.Visible = false
end)
2 Likes

I mean CloseShop Button on the explorer

1 Like

I am pretty sure it works, but then this happens with all the tests.

https://gyazo.com/ee154e92395df607c39786604a6ad0cc
https://gyazo.com/ba705b4875c8e8df1cde7cbc9f9b1468

1 Like

What are those Light blue rounded background? maybe I can configure them too at the script.

1 Like

Those are roundify images to style the mainframe they are test1-test3 in the screengui

1 Like

Is this all of the object in the GUI?

If yes, then try this now:

local MainFrame = script.Parent.Parent:WaitForChild("MainFrame")
local CloseShop = script.Parent
local roundBg1 = script.Parent.Parent:WaitForChild("Test1")
local roundBg2 = script.Parent.Parent:WaitForChild("test2")
local roundBg3 = script.Parent.Parent:WaitForChild("test3")

CloseShop.MouseButton1Down:Connect(function()
	MainFrame.Visible = false
	CloseShop.Visible = false
	roundBg1.Visible = false
	roundBg2.Visible = false
	roundBg3.Visible = false
end)
1 Like

K that will probably work but also when opening the gui at first, it doesnt open together. That is the top code, the first one I sent and it is all the way at the bottom.

1 Like

Maybe put all of this and edit their value to true when you click the OpenShop

    MainFrame.Visible = false
	CloseShop.Visible = false
	roundBg1.Visible = false
	roundBg2.Visible = false
	roundBg3.Visible = false
1 Like

I did that, but it still doesn’t work

1 Like

Umm I confuse about these maybe you edit them like this:

OpenShop.MouseButton1Down:Connect(function() 
MainFrame.Visible = true
 txtbutton.Visible = true
tst1.Visible = true
tst2.Visible = true
tst3.Visible = true
end)