Cam native not working, returns -1

Hi guys, a small (but big question here). I’m trying a piece of camera code which is the following:

local camCoords = {x = 232.51,y = -691.48,z = 82.28, h = 117.65}
local pCoords = vector3(186.16, -718.41, 47.07)
local cam = nil

function Cam(bool)
    if bool then
        ClearFocus()
        SetEntityCoords(PlayerPedId(), pCoords.x, pCoords.y, pCoords.z)
        cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z, 0.0 ,0.0, camCoords.h, 60.00, false, 0)
        SetCamActive(cam, true)
        RenderScriptCams(true, false, 1, true, true)
    else
        ClearFocus()
        SetCamActive(cam, false)
        DestroyCam(cam, true)
        RenderScriptCams(false, false, 1, true, true)
    end
end

RegisterCommand("startcam", function()
    Cam(true)
end)

RegisterCommand("resetcam", function()
    Cam(false)
end)

The problem that i’m having is that there’s no cam made. When i print the variable cam after i created it, it prints -1 where a fivem generated number should be. Am i doing something wrong? If yes please tell me what i did wrong.

Norwedish

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.