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

Camera problems help?

Asked by
iLordy 27
9 years ago
local target = workspace.Part
local camera = 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, 0, 5)       --Move the camera backwards 5 units
    angle = angle + math.rad(1)
end

This code makes the player's camera circle a part when the player enters the game. It works fine but when i add

wait(10)
game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"

to make the camera return back to the player after 10 seconds it just stops making the camera circle/Or it makes the camera circle and comes back to the player but when it comes back to player it makes the camera circle on him.Please help (By the way I put both those local scripts in StarterGui)

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your problem is that you're using an endless while loop to rotate the camera around the part. So when you try to reset it, the loop is still running. You have to combine the two scripts together and make the while loop not endless.

local target = workspace.Part
local camera = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local angle = 0
local rotate = true

camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target

coroutine.wrap(function()
    while rotate == true do
        camera.CoordinateFrame = CFrame.new(target.Position)
                                       * CFrame.Angles(0, angle, 0)
                                       * CFrame.new(0, 0, 5)
        angle = angle + math.rad(1)
    end
end)()

wait(10)
rotate = false
camera.CameraSubject = plr.Character.Humanoid
camera.CameraType = "Custom"
Ad
Log in to vote
1
Answered by
Discern 1007 Moderation Voter
9 years ago

You have your first script in a while loop. When the second script finishes its waiting, the first script will still be running.

If you want to fix this, you could disabled the first script using the second script.

If the first script's name is CircleScript, you could use the second script to destroy (or disable) the first one.

You could make the second script look like this:

wait(10)
game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"
game.Players.LocalPlayer.PlayerGui.CircleScript:Destroy() 

Provided the first script's name is CircleScript, your script would work. If not, you could either just change its name to CircleScript or change CircleScript in line 4 to the name of the first script.

If I helped you, make sure to hit that Accept Answer button below my character! :D

Answer this question