I have this GUI that when you scroll, you can pick options in a list. It works well to start off with because I can select the first option which sends me to a new frame, then I can select "Back" on my new option list which sends me back to the frame I was on before. But it doesn't work when I try it again.

First option selection

I think the error is at the end of this script with the lines of code which print hi,hi2,yesm8

Menu = script.Parent.Menu
MenuBack = script.Parent.MenuBack

options = {"Option1","Option2","Option3","Option4"}
optionselected = 4

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.M then
		if script.Parent.Visible == true then
			script.Parent.Visible = false
		elseif script.Parent.Visible == false then
			script.Parent.Visible = true
		end
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

mouse = game.Players.LocalPlayer:GetMouse()

mouse.WheelBackward:connect(function()
	if Menu.Visible == true then
		optionselected = optionselected + 1
		if optionselected > #options then
			optionselected = 1
		end
		for i,v in pairs(Menu.Options:GetChildren()) do
			if v.Name == options[optionselected] then
				v.BackgroundTransparency = 0.8
			else
				v.BackgroundTransparency = 0.9
			end 
		end
		print(options[optionselected])
	end
end)

mouse.WheelForward:connect(function()
	if Menu.Visible == true then
		optionselected = optionselected - 1
		if optionselected < 1 then
			optionselected = #options
		end
		for i,v in pairs(Menu.Options:GetChildren()) do
			if v.Name == options[optionselected] then
				v.BackgroundTransparency = 0.8
			else
				v.BackgroundTransparency = 0.9
			end 
		end
	end
end)

mouse.Button1Down:connect(function()
	if Menu.Visible == true then
		print("hi")
		Menu.Visible = false
		print("hi2")
		script.Parent:FindFirstChild(options[optionselected]).Visible = true
		print("yesm8")
	end
end)

It prints hi,hi2 and yesm8 even though the the Menu frame doesn't go invisible, and the option frame doesn't go visible

Second option selection

Option = script.Parent

options = {"Back","Option2","Option3","Option4"}
optionselected = 4

mouse = game.Players.LocalPlayer:GetMouse()

mouse.WheelBackward:connect(function()
	if Option.Visible == true then
		optionselected = optionselected + 1
		if optionselected > #options then
			optionselected = 1
		end
		for i,v in pairs(Option.Options:GetChildren()) do
			if v.Name == options[optionselected] then
				v.BackgroundTransparency = 0.8
			else
				v.BackgroundTransparency = 0.9
			end 
		end
	end
end)

mouse.WheelForward:connect(function()
	if Option.Visible == true then
		optionselected = optionselected - 1
		if optionselected < 1 then
			optionselected = #options
		end
		for i,v in pairs(Option.Options:GetChildren()) do
			if v.Name == options[optionselected] then
				v.BackgroundTransparency = 0.8
			else
				v.BackgroundTransparency = 0.9
			end 
		end
	end
end)

mouse.Button1Down:connect(function()
	if optionselected == 1 then
		Option.Visible = false
		Option.Parent.Menu.Visible = true
	end
end)

It sends you back when you select the first option, it sends you back to the frame called menu

The architecture Gyazo Image Link

1 comment

0

I would suggest you to use Values such as ( StringValues, BoolValues, IntValues ) they will make your life simple, and maybe fix your issue ;)!