Can you help me fix this script?

Hiya Developers!

I have a UI which used to open when it was a TextButton, since i changed the TextButton to a ImageButton, the script seems to have stopped working?

Here is the script:

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Next.Visible == false then
		script.Parent.Next.Visible = true
	else
		if script.Parent.Next.Visible == true then
			workspace.Camera.CameraSubject = game.Players.LocalPlayer.Character
			script.Parent.Next.Visible = false
		end
	end
end)

Any help is apricated, thanks!

Is there any error in the output?
Given the fact that you had changed the button to an image button, I’m guessing the problem has to do with your button name. Check that the button name is actually “Next”.

It’d also be a good idea to create a variable for the button instead of having to refer to it every time.
For example

local NextButton = script.Parent.Next

-- Your code here but replace script.Parent.Next with NextButton

Thanks for your suggestion, and there is no error being sent in the Output.

Woops, looking at your code more carefully, it seems like script.Parent is actually your button. So I don’t think my suggestion will work.
Can I see what your explorer looks like?

Yes, here is my explorer.
Explorer

I’d suggest doing some further debugging to find what is and isn’t working in your code.
Something like this.

script.Parent.MouseButton1Click:Connect(function()
    print("Button clicked")
	if script.Parent.Next.Visible == false then
        print("Turning visible")
		script.Parent.Next.Visible = true
	else
        print("Turning invisible")
		workspace.Camera.CameraSubject = game.Players.LocalPlayer.Character
		script.Parent.Next.Visible = false
	end
end)

Also, you don’t need that if script.Parent.Next.Visible == true then when you already have an else statement. After all, there is only two conditions which the visibility can be.

Is the “Next” button in front of the “Open” image button or has a higher zindex?

Thanks, ill run this code now and see if all gets printed in the output.

No, the “Next” button is below then “Open” one.

Here is what i got in the output, it all was printed like expected, but no UI appeared. Output

It appears the code you had specified seems to work perfectly fine. What exactly “isn’t working” after you changed button type?

The “Next” UI will not appear on the screen.

I suggest using a debounce than using the property Visible.

im really suspecting the camera is the prob lel print this again


script.Parent.MouseButton1Click:Connect(function()
    print("Button clicked")
	if script.Parent.Next.Visible == false then
        print("Turning visible")
		script.Parent.Next.Visible = true
	else
        print("Turning invisible")
		workspace.Camera.CameraSubject = game.Players.LocalPlayer.Character
		script.Parent.Next.Visible = false
print("Done")

	end
end)

Thanks ill try this now, ill let you know if “Done” gets printed in the output.

Then the problem is likely with
workspace.Camera.CameraSubject = game.Players.LocalPlayer.Character
Try changing it to
workspace.Camera.CameraSubject =game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")

or Here’s a script using a debounce:

 local debounce = false
 
 script.Parent.MouseButton1Click:Connect(function()
     print("Button clicked")
 	if debounce == false then
         print("Turning visible")
 		script.Parent.Next.Visible = true
 	elseif debounce == true then
         print("Turning invisible")
 		workspace.Camera.CameraSubject = game.Players.LocalPlayer.Character
 		script.Parent.Next.Visible = false
 	end
end)
1 Like

So you are 100% sure that there is not overlapping with open and next? I suspect that the next button is stealing the input.

local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	if not Button.Next.Visible then
		Button.Next.Visible = true
	else
		if Button.Next.Visible then
			workspace.Camera.CameraSubject = game.Players.LocalPlayer.Character
			Button.Next.Visible = false
		end
	end
end)

Thanks ill give this a try now.

Try this:

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Next.Visible == false then
		script.Parent.Next.Visible = true
	else
		if script.Parent.Next.Visible == true then
			workspace.CameraType = Enum.CameraType.Scriptable 
			workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character
			script.Parent.Next.Visible = false
		end
	end
end)
1 Like