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

Camera manipulation script works in studio but not game?

Asked by 8 years ago

At the time of writing this, I've been having trouble for the past few days with getting this camera manipulation script to not only work in studio mode, but also in the actual game. Here is my code:

Localscript:

local target = workspace.MadHotel.MapCutscene.Point2
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Attach
camera.CameraSubject = target
local angle = 0

    target = workspace.MadHotel.MapCutscene.Point2
    i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

target = workspace.MadHotel.MapCutscene.Point3
i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

target = workspace.MadHotel.MapCutscene.Point4
i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

target = workspace.MadHotel.MapCutscene.Point5
i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

    target = workspace.MadHotel.MapCutscene.Point2
    i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

target = workspace.MadHotel.MapCutscene.Point3
i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

target = workspace.MadHotel.MapCutscene.Point4
i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

target = workspace.MadHotel.MapCutscene.Point5
i = 0
while i < 55 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, 0)       --Move the camera backwards 5 units
    angle = angle + math.rad(0.75)
    i = i+1
    wait(0.01)
end

What the code is supposed to do is circle the camera around different parts of the level after certain periods of time, sort of like a quick overview of the level.

I tried putting the main code into a while true loop, copying to each player with a script rather than putting it in startergui, and I have no clue why each time it will work perfectly in Roblox Studio, but not in the actual game. Could someone please help me find a solution to this issue?

1
Sounds silly, but try making the CameraType Scriptable. shayner32 478 — 8y
0
I'm not sure if you can set the CFrame of the camera without setting it to scriptable either, but if it works in studio I assume you can. User#11440 120 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

There are a few things wrong with this script.

The main reason why your code is probably failing is because you're not using WaitForChild.

Along with that, you should be using for loop instead of while loops for what you're doing. It's cleaner and shorter.

Also, Camera.CoordinateFrame is deprecated, as you can see here.

Here's you fixed code,

local MapCut = workspace:WaitForChild("MadHotel"):WaitForChild("MapCutscene")
local target = MapCut:WaitForChild("Point2")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Attach
camera.CameraSubject = target

local angle = 0
for i = 1, 55 do
  camera.CFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 0, 0)
    angle = angle + math.rad(0.75)
    wait()
end

target = MapCut:WaitForChild("Point3")
for i = 1,55 do
  camera.CFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 0, 0)
    angle = angle + math.rad(0.75)
    wait()
end

target = MapCut:WaitForChild("Point4")
for i = 1,55 do
  camera.CFrame = CFrame.new(target.Position) 
                           * CFrame.Angles(0, angle, 0) 
                           * CFrame.new(0, 0, 0)
    angle = angle + math.rad(0.75)
    wait()
end

target = MapCut:WaitForChild("Point5")
for i = 1, 55 do
  camera.CFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 0, 0) 
    angle = angle + math.rad(0.75)
    wait()
end

target = MapCut:WaitForChild("Point2")
for i = 1,55 do
  camera.CFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 0, 0)
    angle = angle + math.rad(0.75)
    wait(0.01)
end

target = MapCut:WaitForChild("Point3")
for i = 1,55 do
  camera.CFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 0, 0) 
    angle = angle + math.rad(0.75)
    wait(0.01)
end

target = MapCut:WaitForChild("Point4")
for i = 1,55 do
  camera.CFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 0, 0)  
    angle = angle + math.rad(0.75)
    wait(0.01)
end

target = MapCut:WaitForChild("Point5")
for i = 1,55 do
  camera.CFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 0, 0) 
    angle = angle + math.rad(0.75)
    wait(0.01)
end

But apart from doing what you're doing, I would suggest using the built in Interpolate function for cameras. Here's the Link. Try it.

Good Luck!

If I helped, please don't forget to accept my answer!
Ad

Answer this question