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

Why this Camera Monitoring script works in Studio mode but not in Online mode?

Asked by 9 years ago

Now this may be a little tricky to explain. I've been creating a camera controlling script to my trusted friends with admin powers that shows them a camera gui and they can monitor the place to check if everything is right.

So far, the script works in studio mode (solo), with the camera change and everything, but on online mode, only the effects and the gui show up. I've already tried to WaitForChild the LocalPlayer property of my localscript. Curiously, my annimation-cancelling script also fails.

Here is the most important part of my script:

repeat wait() until game.Players.LocalPlayer

function wfc(child, parent) return parent:WaitForChild(child) end
function ffc(child, parent) return parent:FindFirstChild(child) end

*snip snap*

local plr = game.Players.LocalPlayer

local currentCamera = nil
local lastCamera = ffc("Corridor1", cameraToggles)
local db = false
local monitorOn = false

function changeCamera(node)
    if monitorOn then
        if ffc(node.Name, cameraStore) then
            local cam = ffc(node.Name, cameraStore)

            videoloss:TweenPosition(UDim2.new(0,0,1,0), 0, 0, .2, false, delay(.2, function() videoloss.Position = UDim2.new(0,0,-1,0) end))
            lastCamera = node

            curCam.CameraType = "Scriptable"
            curCam.CoordinateFrame = cam.CoordinateFrame
            curCam.Focus = cam.Focus
            curCam.FieldOfView = cam.FieldOfView

            currentCamera = node.Name
        end
    end
end

function resetCamera()
    if currentCamera ~= nil then

        curCam.CameraType = "Custom"
        curCam.FieldOfView = 70
        curCam.CameraSubject = ffc("Humanoid", plr.Character)

        currentCamera = nil
    end
end

function monitorCamera()
    if monitorOn == false and db == false then

        db = true

        monitorOn = true
        monitor.Visible = true
        changeCamera(lastCamera)

        videoloss:TweenPosition(UDim2.new(0,0,1,0), 0, 0, .2, false, delay(.2, function() videoloss.Position = UDim2.new(0,0,-1,0) end))

        print('on')
        wait(.3)
        db = false

    elseif monitorOn == true and db == false then
        db = true
        resetCamera()
        monitorOn = false
        monitor.Visible = false
        currentCamera = nil

        print('off')
        wait(.3)
        db = false

    end
end

function hookCameras()
    for _, c in pairs(cameraToggles:GetChildren()) do
        if c:IsA("TextButton") then
            c.MouseButton1Click:connect(
                function()
                    changeCamera(c)
                end
            )
        end
    end
end

function init()
    hookCameras()
end

wait(2)
cameraBut.MouseEnter:connect(monitorCamera)
init()

All of the variables are accordingly declared and no errors pop up in the output or Log window.

Answer this question