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

How can I make this "select" only one UI at a time?

tab = {script.Parent.ScreenGui.one, script.Parent.ScreenGui.two}
function hook()
workspace.remote.OnClientEvent:connect(function(num)
for i,v in ipairs(tab) do
	if v.Value.Value ~= num and v.selected.Value == true then
		v.selected.Value = false
		v.BorderSizePixel = 1
	end
	if v.Value.Value == num then
		script.Value.Value = v.Name
		break
	 end
end
local ui = script.Parent.ScreenGui:FindFirstChild(script.Value.Value)
if ui.selected.Value == true then
	ui.selected.Value = false
	ui.BorderSizePixel = 1
else
ui.BorderSizePixel = 4
ui.selected.Value = true

end


end)
end
hook()

So, this works like it's supposed to, except for the fact that when you press 2, and then 1, it'll select both of the UI's until you press 2 again, which will de-select them both, or 1 again, which will only de-select the UI that corresponds with 1. My question is, how can I make this so that only one of these UI's can be selected at a time, so that if you press 2 then 1, it'll deselect 2 and select one, or vice-versa?

NOTE::: "num" is the button that you've pressed, so if you press 1, "num" will be 1.

1 answer

Nevermind, I fixed it by doing this:

tab = {script.Parent.ScreenGui.one, script.Parent.ScreenGui.two}
function hook()
workspace.remote.OnClientEvent:connect(function(num)
for i,v in ipairs(tab) do
	if v.Value.Value == num then
		script.Value.Value = v.Name
		break
	 end
end
local ui = script.Parent.ScreenGui:FindFirstChild(script.Value.Value)
if ui.selected.Value == true then
	ui.selected.Value = false
	ui.BorderSizePixel = 1
else
ui.BorderSizePixel = 4
ui.selected.Value = true
for i,v in ipairs(tab)do
	if v.Value.Value ~= num and v.selected ~= true then
		v.BorderSizePixel = 1
		v.selected.Value = false
	end
end
end


end)
end
hook()

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