My currently project is making a character selection. There are multiple rosters for each character. I want the rosters to change when you click an arrow going LEFT or RIGHT. Problem is, I have no idea how to shift through the table i have depending on the amount of clicks. Lets say your on the 5th item in the table and click left twice. You’d go to the 3rd once so it’d change a couple things such as images and names. I would love if you could help me!
1 Like
It all depends on how you have set your tables up in the fist instance as to how best to achieve this.
I tend to use nested dictionaries, might not be the best way, but it works for me. For example:
local frame = script.Parent
local maps = {
[1] = {name = "River", level = 0, cost = 0, image = 123456};
[2] = {name = "City", level = 10, cost = 1000, image = 654321};
[3] = {name = "Factory", level = 25, cost = 2000, image = 789456};
};
local currentMap = 1
local function showMap()
frame.TextLabel.Text = maps[currentMap].name
frame.ImageLabel.Image = "rbxassetid://" .. maps[currentMap].image
end
mapUI.btn_Next.Activated:Connect(function()
currentMap += 1 -- increment map no.
if currentMap > #maps then -- check if beyond last map
currentMap = 1
end
showMap()
end)
mapUI.btn_Previous.Activated:Connect(function()
currentMap -= 1 -- increment map no.
if currentMap < 1 then -- check if beyond first map
currentMap = #maps
end
showMap()
end)
Hmm I see, thank you. Although it would be multiple different characters with different amounts of characters… so ig ill figure that out as well.