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

Simple Camera CFrame help?

Asked by 9 years ago

I have a 49 line script, don't worry. I will point out where the errors are. Anyway, every 10 seconds it should change target into CameraPart1 10 seconds later CameraPart2 then 3 and then back to 1. I dont know what the error but I do know where it might be. Please help!

game:GetService("StarterGui"):SetCoreGuiEnabled("All", false) --Ignore
game:GetService("StarterGui"):SetCoreGuiEnabled("Chat", true)

local target = "CameraPart1" --Here?
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 0
local num = 1

while wait() do
    if target == "CameraPart1" then --Here?
    camera.CoordinateFrame = CFrame.new(workspace:FindFirstChild(target).Position) --Here?
                            * CFrame.Angles(0, angle, 0)
        if num == 1 and angle >= 1 then
            num = -1
        elseif num == -1 and angle <= -1 then
            num = 1
        end
    elseif target == "CameraPart2" then
        camera.CoordinateFrame = CFrame.new(workspace:FindFirstChild(target).Position)
                            * CFrame.Angles(angle, 0, 0)
        if num == 1 and angle >= 0.5 then
            num = -1
        elseif num == -1 and angle <= -0.5 then
            num = 1
        end

    elseif target == "CameraPart3" then
        camera.CoordinateFrame = CFrame.new(workspace:FindFirstChild(target).Position)
                            * CFrame.Angles(0.1, angle, 0)
    end
   angle = angle + math.rad(num)
end

while wait(10) do
    target = "CameraPart2" --Here?
    wait(10)
    target = "CameraPart3"
    wait(10)
    target = "CameraPart1"
end

Thanks for your help!


I edited it: It is now only 42 lines.



IT MAY SEEM LIKE A LOT, IT ISN'T, ONLY 5 LINES NEED TO BE FIXED.

1 answer

Log in to vote
0
Answered by 9 years ago

You cannot have two while loops running at the same time. Easy fix is to wrap first loop in a spawn to create a new thread.

game:GetService("StarterGui"):SetCoreGuiEnabled("All", false) --Ignore
game:GetService("StarterGui"):SetCoreGuiEnabled("Chat", true)

local target = "CameraPart1" --Here?
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 0
local num = 1

spawn(function()
while wait() do
    if target == "CameraPart1" then --Here?
    camera.CoordinateFrame = CFrame.new(workspace:FindFirstChild(target).Position) --Here?
                            * CFrame.Angles(0, angle, 0)
        if num == 1 and angle >= 1 then
            num = -1
        elseif num == -1 and angle <= -1 then
            num = 1
        end
    elseif target == "CameraPart2" then
        camera.CoordinateFrame = CFrame.new(workspace:FindFirstChild(target).Position)
                            * CFrame.Angles(angle, 0, 0)
        if num == 1 and angle >= 0.5 then
            num = -1
        elseif num == -1 and angle <= -0.5 then
            num = 1
        end

    elseif target == "CameraPart3" then
        camera.CoordinateFrame = CFrame.new(workspace:FindFirstChild(target).Position)
                            * CFrame.Angles(0.1, angle, 0)
    end
   angle = angle + math.rad(num)
end
end)

while wait(10) do
    target = "CameraPart2" --Here?
    wait(10)
    target = "CameraPart3"
    wait(10)
    target = "CameraPart1"
end
0
Also, cameraSubject = target instead of workspace:FindFirstChild(target). Still doesn't work completely but I fixed it, thanks! EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question