I’m trying to make a location selection, But I’m not sure how to make it “scroll” through my locations
So, you click a button Let’s say this one takes it one up. and it moves one up in the locations, so basically it’ll go from Location1 to Location2, and so forth.
Sorry if this is confusing, I’m not sure how else to explain this.
Let’s say you have a table containing a list of Vector3 positions for the Camera to move between. We’ll also need a counter to keep track of which location we’re currently focusing on.
local locations = {Vector3.new(0,0,0),Vector3.new(10,0,0),Vector3.new(10,0,10)};
local ctr = 1;
The CameraType should be set to Scriptable in order to disable camera movement from the player. game.Workspace.LocalCamera.CameraType = Enum.CameraType.Scriptable;
Now, when the button is clicked, we can have it connected to an event which uses Camera:Interpolate() to tween the camera from where it is to the desired location.
function nextLocation()
ctr = ctr%#locations+1; --Counts up to the length of the table, then resets to 1
game.Workspace.LocalCamera:Interpolate(CFrame.new(locations[ctr]),CFrame.new()),2); --Moves from the current location to the next location over the course of 2 seconds, keeping the camera focused at 0,0,0
end
button.MouseButton1Click:Connect(nextLocation); --Assuming button is a reference to your GUIButton
Messing with the above code should get you what you’re looking for. Cheers
I did have to mess with it alot, Seeing as I wasn’t specific enough to specify it was objects, But your script worked perfectly for me! Just one question, Any way I could make it go backwards too?