Getting error when using GetVehiclePedIsIn function

I just started writing scripts, and I really need help. Here is my code:

RegisterCommand('rescar', function(source, args, rawCommand)
    if(source > 0) then
        local vehId = GetVehiclePedIsIn(source, false)
        if vehId ~= 0 then
            TriggerClientEvent('chat:addMessage', source, {
                color = {220,220,220},
                multiline = true,
                args = {"[RESCAR]", string.format("Your vehicle: %s", GetEntityModel(source))}
            })
        end
    end
end, false)

For now it should just print the type of car the player is in, but when I run it, I get this error message:

SCRIPT ERROR: @rescar/server.lua:3: attempt to call a nil value (global 'GetVehiclePedIsIn')

Also, here is my fxmanifest.lua:

fx_version 'bodacious'
game 'gta5'

author 'Simi23'
description 'A script which respawns your car with the same handling'
version '1.0.0'

server_script 'server.lua'

What am I doing wrong?

Because You can only call “GetVehiclePedIsIn” in client and You’re calling it in server

Thank you! Btw, the reference suggests it is reference suggests it’s a server-side function, this got me confused.

1 Like

It’s a server side function but only if Onesync is enabled. You can get more informations here : OneSync+ and future work on OneSync