local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local TweenService = game:GetService("TweenService")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer.PlayerGui
local jobView = PlayerGui:FindFirstChild("JobView").BG_Frame
local cameraRegions = workspace.CameraView
local cameraTable = {
policeOfficer = cameraRegions.PoliceOfficer,
doctor = cameraRegions.Doctor,
Cafe = cameraRegions.Cafe
}
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local function nextButtonClicked()
for i, v in pairs(cameraTable) do
v = next(cameraTable)
print(v)
end
end
jobView.NextClick.MouseButton1Down:Connect(nextButtonClicked)
I am trying to make a table, and I am testing it to see if it prints (V), which it does not. I do not have an error.
Since cameraTable is not empty, printing the contents of it will print something. Since nothing prints, that means nextButtonClicked is never called. Did you click on the jobView gui? do you know whether this script runs at all?
In your cameraTable table, you are explicitly assigning values to indices (or properties). The “i” (index) in the for loop is the property the iterator function is currently on (in this case pairs) and the “v” (value) is the value the iterator function is on. The reason it’s printing out “Doctor” is because you’re printing out each value of the table instead of each index (or property). My guess is it prints out “Doctor” because casting an instance to a string usually results in just the name of the instance, not the full path.
To access each index (which is what it sounds like you want to do) just replace v with i in your print function call.
I am trying to make it print the next item in the table each time I click on the next button. If I click the next button from 0, it will print 1. From 1, it prints 2 and so on
In this case, I would make a separate variable that gets incremented like so every time you click the button:
local currentSubject = 1
...
--- Do this whenever you want to change the subject of the camera --
currentSubject = ((currentSubject + 1) % 3) + 1 -- 1, 2, 3, 1, 2, 3, 1...
You probably want to add the % 3 at the end to make sure that it loops back to zero once it reaches 3.
Be aware that it may be difficult to get the exact order of the list if you use strings as indices. I believe the built in iterator functions iterate over it in alphabetical order rather than the order you put them in your script. You might want to also assign an id to each index in addition to your cameraRegions. You can do this by replacing each value with:
Make a variable that holds the current index of the camera they’re viewing.
After adding one to the current index, if it is greater than the total number of cameras in the table, you’ll want to reset it back to the first index.