Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

help me with my open close shop button? It dosen't work no error code or anything (SOLVED)

So what it supposed to do is say open when the shop frames isn't visible and when the frames are visible it should say close. but it dosen't work.

script.Parent.OpenClose.MouseButton1Click:Connect(function()
	local scp = script.Parent
	local Main = script.Parent.OpenClose
	
	if scp.Frame.Visible == false then
		Main.Text = "Open"
		scp.Item1.Visible = true
		scp.Item2.Visible = true
		scp.Frame.Visible = true
		end
		
	if scp.Frame.Visible == true then
	Main.Text = "Close"
		scp.Item1.Visible = false
		scp.Item2.Visible = false
		scp.Frame.Visible = false
	
	end
end)

Extra information/how gui's are set up.

https://ibb.co/dMzfRbR

Help would be appreciated, thanks

1 comment

1

you could just set scp's visibility

1 answer

✓ Accepted answer

ISSUE

While the code should work perfectly fine, you need to place this into a :LocalScript since StarterGuis can only be run on the Client.

GENERAL PRACTICE

Move the defined variables outside the function and use them for the connection as well.

Use :WaitForChild() to make sure a part exists before using it.

Use Activated instead of MouseButton1Click since Activated works for all devices and not just computers

You can use elseif to check a different property of the frame instead of using two separate if-then statements

Revised LocalScript

local scp = script.Parent
local Main = scp:WaitForChild("OpenClose")

Main.Activated:Connect(function()
	if scp:WaitForChild("Frame").Visible == false then
		Main.Text = "Open"
		scp:WaitForChild("Item1").Visible = true
		scp:WaitForChild("Item2").Visible = true
		scp:WaitForChild("Frame").Visible = true
	elseif scp:WaitForChild("Frame").Visible == true then
		Main.Text = "Close"
		scp:WaitForChild("Item1").Visible = false
		scp:WaitForChild("Item2").Visible = false
		scp:WaitForChild("Frame").Visible = false
	end
end)

1 comment

1

Thnk You so much for the advice, an the fixed script SerpentineKing

This discussion is preserved as it was. New answers, comments, and votes are closed.