You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
What I want to achieve is to make sure that the next() function actually goes in order (which I could try ipairs but not sure how I would put it into the script.)
The order should move like this; 1,2,3,4,5, etc instead of it moving as a random selection or moving backward. -
What is the issue? Include screenshots / videos if possible!
The issue is that when the function is fired, Instead of it going in order each time, It goes from the first option to the last and then goes in reverse, Which is quite strange. An image of the output shows that it goes from the 1st option To the very last as you can see here;

-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried using ipairs, but for some reason, but since this is a dictionary, I’m quite confused - They arent exactly the same as arrays but similar. I’ve also tried to look for solutions on developer hub, Which I copied the same exact script - well not exactly the same but in a way where it should work the same way and it didn’t work.
The script is provided below;
local camerasConfig = {
["PreviewCam"] = nil
,["TourCam1"] = "text input 1"
,["TourCam2"] = "text input 2"
,["TourCam3"] = "text input 3"
,["TourCam4"] = "text input 4"
}
local currentCam = config.CameraName -- config is a module script - CameraName is 'PreviewCam'
local nextCam, val = next(camerasConfig, currentCam)
local btn = script.Parent.button -- this button was for testing purposes to fire the function.
function moveToNext()
print(currentCam, nextCam)
currentCam = nextCam
nextCam, val = next(camerasConfig, currentCam)
end
btn.MouseButton1Click:Connect(function()
moveToNext()
end)
What’s supposed to happen is that it’s meant to go from PreviewCam to TourCam1 and so on in order. Although it’s not doing that and I don’t know why.
If you guys could help, I would be thankful.
