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

Camera LocalScript Not Functioning?

Asked by
sammiya1 134
8 years ago
local rooms = game.Workspace:WaitForChild("Rooms")
local camera = game.Workspace:WaitForChild("Rooms"):WaitForChild("Camera1")
local target = game.Workspace:WaitForChild("Rooms"):WaitForChild("Target1")
local cam = game.Workspace.CurrentCamera
local Button = script.Parent


function SendCamera()
wait(10)
cam.CameraSubject = camera
cam.CameraType="Custom"
cam.Focus=CFrame.new(target.Position)
cam.CoordinateFrame= CFrame.new(camera.Position)
end

if cam.Cameratype="Custom" then
cam.Cameratype="Scriptable"
Button.MouseButton1Click:connect(SendCamera)

Tried all possible with this and it wont work

1 answer

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

Where to start?

I'll be very pedantic and picky so you can make the most out of your code! The more efficient the better! If this still doesn't work, try rethinking the algorithm as I've no idea what it's supposed to be doing.

local rooms = game.Workspace:WaitForChild("Rooms") -- make sure these all exist first, the new updates should mean that warnings are triggered if this is the reason for its failure.
local camera = game.Workspace:WaitForChild("Rooms"):WaitForChild("Camera1")
local target = game.Workspace:WaitForChild("Rooms"):WaitForChild("Target1")
-- ^ change the "game.Workspace:WaitForChild("Rooms")" in camera and target to just "rooms"
-- (sorry for being pedantic xD)
local cam = game.Workspace.CurrentCamera
local Button = script.Parent


function SendCamera()
    wait(10) -- Is this wait meant to be here? Just curious
    cam.CameraSubject = camera
    cam.CameraType="Custom" -- THIS NEEDS TO BE SCRIPTABLE (Enum.CameraType.Scriptable)
    cam.Focus=CFrame.new(target.Position)  -- this doesn't include rotation, change this to "cam.Focus=target.CFrame"
    cam.CoordinateFrame= CFrame.new(camera.Position) -- this too doesn't include rotation, change this to "cam.CoordinateFrame=camera.CFrame"
end

if cam.Cameratype="Custom" then -- Two errors here: 1) should be CameraType not Cameratype
--2) needs to be == not = as this is a conditional statement not the setting of a variable
    cam.CameraType="Scriptable" -- CameraType not Cameratype
    Button.MouseButton1Click:connect(SendCamera)
-- Where's the end? (Might be missing from this extract, my bad if that's the case!)

Cheers :) CD

Ad

Answer this question