So I was learning about Camera Manipulation, and when I tested it out, all of a sudden my character flips out for no reason when I move... Is there a reason why it does that, and how can I fix it?
Here's a link to the video demonstrating my player freaking out.
Link: https://youtu.be/xhN3O9pm9yE
And here's the code for the Camera Manipulation:
local target = game.Workspace.SpawnLocation local camera = game.Workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target local angle = 0 while wait() do camera.CoordinateFrame = CFrame.new(target.Position) --Start at the position of the part * CFrame.Angles(0, angle, 0) --Rotate by the angle * CFrame.new(0, 10, 30) --Move the camera backwards 30units, 10 units up angle = angle + math.rad(1) script.Parent.Play.MouseButton1Click:connect(function() script.Parent.Play.Visible = false game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid game.Workspace.CurrentCamera.CameraType = "Custom" end) end
And if you'd like to check out the place for yourself, here's the link to that, too.
Link: http://www.roblox.com/games/322474814/Donations
Note: Don't mind the donations thing for my place, I used to have BC, but it expired, so I wanted to use the script at the place of Donations. Also, I learned this information from Roblox Wikipedia... If that helps at all :P
Thank you :)
The camera will not stop rotating after clicking Play. What's worse, you're making multiple connections to the same event every time the loop is run (line 13
). I would suggest putting the connection to the MouseButton1Click
event above the loop, and making the loop stop after the player clicks play.
local target = game.Workspace.SpawnLocation local camera = game.Workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target local angle = 0 --if the player clicks the play button, set this value to true local IsPlaying = false script.Parent.Play.MouseButton1Click:connect(function() -- sets IsPlaying to true, now we can stop the loop IsPlaying = true script.Parent.Play.Visible = false -- You may want to set the `Enabled` property to false, too. game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid game.Workspace.CurrentCamera.CameraType = "Custom" end) -- while the player isn't playing, rotate the camera while not IsPlaying do camera.CoordinateFrame = CFrame.new(target.Position) --Start at the position of the part * CFrame.Angles(0, angle, 0) --Rotate by the angle * CFrame.new(0, 10, 30) --Move the camera backwards 30units, 10 units up angle = angle + math.rad(1) -- move the wait down here wait() end