Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Camera Manipulation and TextButton Help?

Asked by 9 years ago

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:

01Torso = script.Parent.Parent.Parent.Parent.Parent.Character:WaitForChild("Torso")
02 
03MouseLeave = script.Parent.MouseLeave
04 
05 
06script.Parent.MouseEnter:connect(function(mouse)   
07target = workspace.CP2.SpawnLocation
08local camera = workspace.CurrentCamera
09camera.CameraType = Enum.CameraType.Scriptable
10camera.CameraSubject = target
11local angle = 0
12 
13while wait() do
14    camera.CoordinateFrame = CFrame.new(target.Position) 
15                           * CFrame.Angles(0, angle, 0)
View all 27 lines...

1 answer

Log in to vote
4
Answered by 9 years ago

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.

01Torso = script.Parent.Parent.Parent.Parent.Parent.Character:WaitForChild("Torso")
02 
03MouseLeave = script.Parent.MouseLeave
04 
05 
06script.Parent.MouseEnter:connect(function(mouse)
07MouseEntered = true --Mouse is hovering over button 
08target = workspace.CP2.SpawnLocation
09local camera = workspace.CurrentCamera
10camera.CameraType = Enum.CameraType.Scriptable
11camera.CameraSubject = target
12local angle = 0
13 
14while MouseEntered do -- while mouse is hovering repeat this code
15    camera.CoordinateFrame = CFrame.new(target.Position) 
View all 30 lines...

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 — 9y
0
THANKS!!! dragonkeeper467 453 — 9y
Ad

Answer this question