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

How to script a navigation bar in a wiki GUI?

I'm creating an RPG, and I have begun adding a custom in-game wiki on the game's lore. I have completed the navigation bar of the wiki, which contains a list of all the pages I plan to add in the wiki. The list is a bunch of TextButtons put on top of one another, but I have no idea how to script the buttons so that they open their respective pages when clicked.

Image of the wiki GUI: http://i.imgur.com/WPbDXjH.png

The GUI in the Explorer: http://i.imgur.com/T9NpGQ6.png

2 comments

0

Look into using the MouseButton1Down event, and the 'Visibility' property for frames. It's difficult to answer this question due to how elaborate your gui is.

0

I've thought about using that, but how would I close an already open page when another button is pressed?

1 answer

What you want to do here is 'link' different objects. In this case, a Frame and a TextButton. This is the explorer view of what it should look like in the above situation.

  • ScreenGui
    • LocalScript (that handles the wiki)
    • WikiFrames
      • Hoole (frame with Visible set to false)
    • WikiButtons
      • Hoole (button)

What you want to do is iterate through a table of all of the buttons. Then, when the button gets clicked, it searches for a corresponding frame to the button that got clicked. It then toggles the frame from there.

The following code should be inside the LocalScript shown above:

local g = script.Parent -- the screengui
local frames = g:WaitForChild("WikiFrames") -- the holder of the frames
local buttons = g:WaitForChild("WikiButtons") -- the holder of the buttons

local currentFrame -- the current frame that is open

for _,v in pairs (buttons:GetChildren()) do -- all of the buttons
	v.MouseButton1Down:connect(function() -- when the button is clicked
		local f = frames:FindFirstChild(v.Name) -- the corresponding frame
		if f then -- if the frame is found
			if f == currentFrame then -- if the frame is already open
				f.Visible = false -- closes frame
			else
				if currentFrame then -- if there is another frame open
					currentFrame.Visible = false -- hides that frame
				end
				currentFrame = f -- sets the current frame to the button's frame
				currentFrame.Visible = true -- opens it
			end
		end
	end
end

If you need more, I am happy to help. You may need help converting this script to work completely with your GUI.

EDIT:

Alternately, you could make a large dictionary with individual values, and have only one frame with some TextLabels inside it that get changed when one of the values-inside-the-dictionary's corresponding button is clicked.

This solution may be more efficient, and faster/easier to create.


Hope I helped!

~TDP

2 comments

0

I think it worked! I won't know for sure until it's completely implemented, but from what I've seen from a simple test I think we've got it. Thank you so much!! :D

0

No problem! I'm glad to help.

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