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

How would I stop this loop and make the camera return to normal?

Asked by 6 years ago
Edited 6 years ago

I've been trying to stop the loop and make the camera focus on the player but it won't seem to work. I've tried removing the rotation point, the script itself, making a value etc but it just won't seem to work.

local target = workspace.Terrain local value1 = script:WaitForChild("Value")~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~

local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target --camera.Focus = CFrame.new(target.Position) local angle = 0 local i = 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, 50, 50) --Move the camera backwards 5 units --camera.Focus = CFrame.new(target.Position) angle = angle + math.rad(1)

if value1.Value == true then break end

end im new to scripting so anything that could help is appreciated :)

0
You messed up your code break there GamingOverlord756 48 — 6y
0
rip DaWarTekWizard 169 — 6y
0
instead of "break end" do "return end" or just "break" DeceptiveCaster 3761 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Well, if you want to return the camera to it's "normal" self you'd store camera settings before it's changed then revert it back.

-- Local Script
local target = workspace.Terrain 
local BoolValue = Instance.new("BoolValue",workspace)
local camera = workspace.CurrentCamera 
local oldCameraType, oldCameraSubject = nil

BoolValue.Value = true

-- Waits for humanoid to load
repeat wait() until camera.CameraSubject

oldCameraType = camera.CameraType
oldCameraSubject = camera.CameraSubject
camera.CameraType = Enum.CameraType.Scriptable 
camera.CameraSubject = target --camera.Focus = CFrame.new(target.Position) local angle = 0 local i = 0

spawn(function()
    wait(2)
    BoolValue.Value = false
end)

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, 50, 50) 
    --Move the camera backwards 5 units 
    --camera.Focus = CFrame.new(target.Position) angle = angle + math.rad(1)
    if BoolValue.Value == false then 
        camera.CameraType = oldCameraType
        camera.CameraSubject = oldCameraSubject
        print(camera.CameraType)
        print(camera.CameraSubject)
        break 
    end
end

print("Loop ended")

If your CameraSubject is not Humanoid when the loop ends then you'll have to make sure to check that Humanoid exists before changing the camera.

Ad

Answer this question