Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would you make a camera switch in order in a gui?

I'll try my best to explain this. In my scripts, I made a pop up gui that sets a CameraSubject on a part. I want it where you would click a next button and it would make your CameraSubject on another part and so on to the parts after. If you click a previous button, it will make your CameraSubject go back to the first part and so on to the parts before. I've tried using a number value method where a certain part was defined as a number value. I'm currently trying to use tables and object values but I still have no clue on what to do.

Current script:

reference = {"M9","Desert Eagle","Beretta 93R","M16A3","M1014","Galil AR","M249 SAW"} --nothing here just something to help me correctly spell the names
guns = {"M9"} --a new table that could be added to
gui = script.Parent
value = gui:WaitForChild("Cam") --object value
Next = gui:WaitForChild("Next")
previous = gui:WaitForChild("Previous")
name = gui:WaitForChild("Name")
local cam = game.Workspace.CurrentCamera
name.Text = value.Value.Name
cam.CameraSubject = value.Value

--no idea how to transition the value in order from the reference table on the first line
Next.MouseButton1Click:connect(function()
	name.Text = value.Value.Name
	cam.CameraSubject = value.Value
end)

previous.MouseButton1Click:connect(function()
	name.Text = value.Value.Name
	cam.CameraSubject = value.Value
end)

1 answer



--ALL YOUR VARIABLES


--Btw, in this script, reference has all the paths to the guns, im leaving the table like it is, but
--Remember that.
--for example: reference=
--{game.ReplicatedStorage.M9,game.ReplicatedStorage.DesertEagle}


reference = {"M9","Desert Eagle","Beretta 93R","M16A3","M1014","Galil AR","M249 SAW"} --nothing here just something to help me correctly spell the names

guns = {"M9"} --a new table that could be added to
gui = script.Parent
name= gui:WaitForChild("Name")
local cam = game.Workspace.CurrentCamera
name.Text = value.Value.Name
cam.CameraSubject = value.Value

--SETING CAM,NEXT,AND PREVIOUS (to their order number)(they are now the order of the ---guns in the table)

value = 1
previous = #reference
next = 2

--MAKES CAMERA SUBJECT FIRST THING IN THE TABLE
cam.CameraSubject = refrence[1]



Next.MouseButton1Click:connect(function()
   -- UPDATES COUNTERS
    value = value +1
    previous = value - 1
    Next = value +1 

   --PREVENTS COUNTER OVER FLOW
    if previous == 0 then
    previous = #refrence
    end
    if Next == #refrence +1 then
    Next = 1
    end
   
    name.Text = refrence[value].name
    cam.CameraSubject =refrence[value]
end)

Next.MouseButton1Click:connect(function()
   -- UPDATES COUNTERS
    value = value -1
    previous = value - 1
    Next = value +1 

   --PREVENTS COUNTER OVER FLOW
    if previous == 0 then
    previous = #refrence
    end
    if Next == #refrence +1 then
    Next = 1
    end
   
    name.Text = refrence[value].name
    cam.CameraSubject =refrence[value]
end)


I hope this works! (Check all my comments in the script to see what I changed

1 comment

0

Thanks I edited it a little but it still works

This discussion is preserved as it was. New answers, comments, and votes are closed.