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)
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
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?
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.
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")
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)
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)