You can use "setPedCanBeKnockedOffBike" function but its server sided, also there is no such function "setElementGravity" at least not on MTA there are setVehicleGravity and setPedGravity
server-side:
function teleportVehicle(player, command, x, y, z)
if not isPedInVehicle(player) then
outputChatBox("You must be in a vehicle to use this command.", player, 255, 0, 0)
return
end
local playervehicle = getPedOccupiedVehicle(player)
if not x or not y or not z then
outputChatBox("Usage: /tp [X] [Y] [Z]", player, 255, 0, 0)
return
end
x = tonumber(x)
y = tonumber(y)
z = tonumber(z)
if not x or not y or not z then
outputChatBox("Invalid coordinates.", player, 255, 0, 0)
return
end
triggerClientEvent(player, "onClientTeleportVehicle", player, x, y, z)
outputChatBox("Vehicle teleported to coordinates: "..x..", "..y..", "..z, player, 0, 255, 0)
end
addCommandHandler("tp", teleportVehicle)
client-side:
function tp(x, y, z)
local player = getLocalPlayer()
local playervehicle = getPedOccupiedVehicle(player)
setElementPosition(playervehicle, x, y, z)
setPedCanBeKnockedOffBike(player, false)
setTimer(function() setPedCanBeKnockedOffBike(player, true) end, 1000, 1)
end
addEvent("onClientTeleportVehicle", true)
addEventHandler("onClientTeleportVehicle", root, teleportVehicle)
don't mind the command and all the error handling I've built it to try it tho, I wanted to see if to set its Gravity will fix it