Gui and Camera failing

So, When you click on a button it changes the position of the camera. Simple, but I am having insane failure.
I’ve tried to debug this for over an 2 hours so I’m desperate for answers. The script is a local script.

local Gui = script.Parent.Parent
local Number = Gui.Number
local CommonFrame = Gui.ScrollingFrame
local RareFrame = Gui.RareRequirements
local EpicFrame = Gui.EpicRequirements
local CurrentCam = workspace.CurrentCamera

local commoncam = workspace.ChiikenShop.CommonChiiken.camera
local rarecam = workspace.ChiikenShop.RareChiiken.camera
local epiccam = workspace.ChiikenShop.EpicChiiken.camera

local clicks = 1

script.Parent.MouseButton1Click:Connect(function()
	clicks += 1
	print("clicked")
	if Number.Value == 1 then
		print("1 fired")
		RareFrame.Visible = true
		CurrentCam.CameraType = Enum.CameraType.Custom
		CurrentCam.CameraType = Enum.CameraType.Scriptable
		CurrentCam.CFrame = rarecam.CFrame
		wait(1)
		repeat
			wait(0.1)
		until
		clicks == 2
		print("click1")
		Number.Value = 2
		RareFrame.Visible = false
	end
	
	
	if Number.Value == 2 then
		print("2 fired")
		EpicFrame.Visible = true
		CurrentCam.CameraType = Enum.CameraType.Custom
		CurrentCam.CameraType = Enum.CameraType.Scriptable
		CurrentCam.CFrame = epiccam.CFrame
		wait(1)
		repeat
			wait(0.1)
		until
		clicks == 3
		print("Click2")
		Number.Value = 3
		EpicFrame.Visible = false
	end
	
	
	if Number.Value == 3 then
		print("3 fired")
		CommonFrame.Visible = true
		CurrentCam.CameraType = Enum.CameraType.Custom
		CurrentCam.CameraType = Enum.CameraType.Scriptable
		CurrentCam.CFrame = commoncam.CFrame
		wait(1)
		repeat
			wait(0.1)
		until
		clicks == 4
		print("CLICK3")
		Number.Value = 1
		CommonFrame.Visible = false
		clicks = 0
	end
end)

There are no errors or warnings, just the things I printed in that script.
However, only the first if statement fires. I am unsure why or how.

Try replacing the 2 bottom if statements to elseif statements.

1 Like

No. That does not work. It helped organize my code but it does not work.

So you are setting the click value to 1,

then you are adding a click when you click the thing. That would not make sense because for the first one, you are running a statement when the clicks = 1, that would not be true because Clicks = 2. That would break the whole script. You need to fix that

maybe it is a problem with a local script trying to update the number value

try making the if statements check for the value of clicks instead of Number.Value, like if clicks == 1 then etc.

Nope. That does not work. In fact, the first round you go through is the same problem as mine, but then the second round suddenly stops working.

Surprisingly, it did not work. I simply just changed the starting click value to 0 instead of 1 so the first if statement would fire but it did not fire.

does it ever print ‘click1’?, where exactly is the code failing to run

it ONLY prints “click1”. The reason of this post is to figure out why it only ever prints “click1”

ok at the very top of the function put print(Number.Value) to see whether or not the number is changing

image

As you can see here, the value starts at 1, then changes to 2 in around 4 clicks. (too lazy to count). It then continues with 2 forever (I think).

you said you have clicks initialized to 0, so

first click:

  • sets clicks to 1
  • runs the first if statement which proceeds to wait for clicks == 2

second click:

  • sets clicks to 2
  • runs the first if statement again because Number.Value is still 1
  • the wait for clicks == 2 from the first click now fires and sets Number.Value to 2
  • the wait for clicks == 2 from this click passes because clicks is 2 (doesnt do anything since number is already 2)

third click:

  • sets clicks to 3
  • runs the second if statement, which proceeds to wait for clicks == 3. clicks is already 3 so it just needs to wait the 1 second before it can pass the repeat loop to set Number.Value to 3

if you now click a 4th time before that until clicks == 3 passes, you now set clicks to 4, and that old repeat loop waiting for clicks == 3 will never pass. you will be forever stuck to Number.Value being 2

overall, your code is kinda jank you might need to reformat it lol

local Gui = script.Parent.Parent
local Number = Gui.Number
local CommonFrame = Gui.ScrollingFrame
local RareFrame = Gui.RareRequirements
local EpicFrame = Gui.EpicRequirements
local CurrentCam = workspace.CurrentCamera

local commoncam = workspace.ChiikenShop.CommonChiiken.camera
local rarecam = workspace.ChiikenShop.RareChiiken.camera
local epiccam = workspace.ChiikenShop.EpicChiiken.camera

local clicks = 0

script.Parent.MouseButton1Click:Connect(function()
	clicks += 1

	if clicks == 1 then
       Number.Value = 1
		RareFrame.Visible = true
        EpicFrame.Visible = false
        CommonFrame.Visible = false
		CurrentCam.CameraType = Enum.CameraType.Custom
		CurrentCam.CameraType = Enum.CameraType.Scriptable
		CurrentCam.CFrame = rarecam.CFrame
	elseif clicks == 2 then
        Number.Value = 2
		RareFrame.Visible = false
        EpicFrame.Visible = true
        CommonFrame.Visible = false
		CurrentCam.CameraType = Enum.CameraType.Custom
		CurrentCam.CameraType = Enum.CameraType.Scriptable
		CurrentCam.CFrame = epiccam.CFrame
	elseif clicks == 3 then
        Number.Value = 3
		RareFrame.Visible = false
        EpicFrame.Visible = false
        CommonFrame.Visible = true
		CurrentCam.CameraType = Enum.CameraType.Custom
		CurrentCam.CameraType = Enum.CameraType.Scriptable
		CurrentCam.CFrame = commoncam.CFrame
	elseif clicks >= 4 then
        Number.Value = 1
        RareFrame.Visible = false
        EpicFrame.Visible = false
        CommonFrame.Visible = false
        clicks = 0
    end
end)

im not sure if i got down exactly what you were trying to do, but this should solve the problem of it not running

Alright, Thank you! There is a slight problem with the CFrame camera but i’ll fix it. You’ve saved 1 week of debugging!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.