2

# Camera Manipulation and TextButton Help?

I have two TextButtons, when you hover over one, it changes the camera to a Control point and spins it around.

It works with one Gui button, but if you hover over another one, it glitches out and changes the camera to one or the other rapidly.

Any way how to fix this? I've heard of breaking the loop, but I don't know how to break it after the chunk of code.

Here's the script inside the button:

Torso = script.Parent.Parent.Parent.Parent.Parent.Character:WaitForChild("Torso")

MouseLeave = script.Parent.MouseLeave

script.Parent.MouseEnter:connect(function(mouse)
target = workspace.CP2.SpawnLocation
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 0

while wait() do
camera.CoordinateFrame = CFrame.new(target.Position)
* CFrame.Angles(0, angle, 0)
* CFrame.new(0, 0, 15)

end
end)

script.Parent.MouseButton1Down:connect(function(bloop)
game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"
Torso.CFrame = CFrame.new(target.Position)
script.Parent.Parent.Parent:Destroy()
end)


4

Its obviously getting stuck in the while wait() do loop. You probably want to use a boolean to control the while wait do loop.

Basically, I added a boolean called MouseEntered which stands for if the mouse entered the button, it then repeats the code previously surrounded with while wait() do, but this time it is controlled by a boolean, so while MouseEntered is true, it will run that code. Then you have to add the wait into the while MouseEntered do loop so that it doesn't crash. Lastly, when the MouseButton1Down is called it stops the while MouseEntered loop by setting MouseEntered to false.

If you go back to the MouseEntered function it will resume the while MouseEntered loop.

Torso = script.Parent.Parent.Parent.Parent.Parent.Character:WaitForChild("Torso")

MouseLeave = script.Parent.MouseLeave

script.Parent.MouseEnter:connect(function(mouse)
MouseEntered = true --Mouse is hovering over button
target = workspace.CP2.SpawnLocation
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 0

while MouseEntered do -- while mouse is hovering repeat this code
camera.CoordinateFrame = CFrame.new(target.Position)
* CFrame.Angles(0, angle, 0)
* CFrame.new(0, 0, 15)
wait()

end
end)

script.Parent.MouseButton1Down:connect(function(bloop)
MouseEntered = false -- the mouse is no longer just hovering, stops the while loop
game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"
Torso.CFrame = CFrame.new(target.Position)
script.Parent.Parent.Parent:Destroy()
end)



Please let me know if this does not work, dont forget to leave a rep and mark my answer as correct if this is helpful, any tips on how to improve my answers are appreciated!

0
Exactly what I would've done. Nice answer(: Goulstem 8144 — 7y
0
THANKS!!! dragonkeeper467 453 — 7y