Help with arrays

I’m trying to make a character creation menu and I’m trying to make it so you click through some arrows and each time you click an arrow the corresponding UI will come up on the screen (as well as change the name of the text label, which I’ll show below)

image

The code I have so far for this is:

local SelectionArray = {"Hair", "Skin", "Beard", "Face", "Shirts", "Pants"}
local SelectionIndex = 1


script.Parent.Activated:Connect(function()
	SelectionIndex += 1 
	game.Players.LocalPlayer.PlayerGui.ScreenGui.CharacterCreationUI.Main.Selection.SelectionGroupUI.Text = SelectionArray[2]
	game.Players.LocalPlayer.PlayerGui.ScreenGui.CharacterCreationUI.Main.Selection.Backwards.Visible = true
end)

I’m not quite sure what to do next to achieve what I’m trying to do. Any help is appreciated, if I didn’t explain something clearly enough let me know and I’ll go into further detail… Like I said any help is appreciated

also i’m very new to scripting

3 Likes

Can you send the hierarchy in the explorer so I can see how it’s structured?

2 Likes

image

The folders labeled Shirts, Pants, etc are just organizational folders and house the UI for those specific things. The LocalScript under the “Forwards” TextButton is the script that is in the post.

3 Likes

What you’d do is Main[SelectionArray[SelectionIndex]] to index to the correct folder. Under that folder you’d want indentical named elements so you can toggle their visibility

2 Likes

I’m not quite sure what you mean (im new to scripting, arrays are VERY VERY new to me)

Also, what about changing the text label (SelectionGroupUI TextLabel) to tell the user which ‘tab’ there on? Would I just keep doing what I’m doing and set the text in the text label to the index in the SelectionArray? (example: TextLabel.text = SelectionArray[2])

2 Likes
local Players = game:GetService("Players")

local SelectionArray = {"Hair", "Skin", "Beard", "Face", "Shirts", "Pants"}
local SelectionIndex = 1

local selectionUI = Players.LocalPlayer.PlayerGui.ScreenGui.CharacterCreationUI.Main.Selection

script.Parent.Activated:Connect(function()
    if SelectionIndex < #SelectionArray then
        SelectionIndex += 1
        selectionUI.Backwards.Visible = true
    else
        SelectionIndex = 1
        selectionUI.Backwards.Visible = false
    end

	selectionUI.SelectionGroupUI.Text = SelectionArray[SelectionIndex]
end)

3 Likes

This does work, thank you.

I have one more question, though:
Since there is other UI assosciated with this, how would I go about making that UI visible each time the arrow is pressed?

What do the paths look like? Can you ss the explorer view

image

Each folder is an organizational folder, they house the UI.

1 Like

whats in the other folders?

What do you mean? In the other folders there is UI… Like i said

They have UI in them which are the “tabs” you switch to with the arrows.

Yeah what are the names of the uis in them?

Here’s a sample script you can use:

local Players = game:GetService("Players")

local SelectionArray = {"Hair", "Skin", "Beard", "Face", "Shirts", "Pants"}
local SelectionIndex = 1

local mainUI = Players.LocalPlayer.PlayerGui.ScreenGui.CharacterCreationUI.Main
local selectionUI = mainUI.Selection
local uiPath

script.Parent.Activated:Connect(function()
    if SelectionIndex < #SelectionArray then
        SelectionIndex += 1
        selectionUI.Backwards.Visible = true
    else
        SelectionIndex = 1
        selectionUI.Backwards.Visible = false
    end

    if uiPath then
        uiPath.Visible = false
    end

    uiPath = mainUI:FindFirstChild(SelectionArray[SelectionIndex]):FindFirstChild("name of ui inside folder")

    if not uiPath then
        warn("UI not found")
        return
    end

    uiPath.Visible = true
	selectionUI.SelectionGroupUI.Text = SelectionArray[SelectionIndex]
end)