alienwave 0 Posted November 1 (edited) let vehicle = mp.players.local.vehicle; let counter = { init() { let speed = vehicle.getSpeed() * 3.6; timerBars.speedBar.text = `${speed}`; } } function playerEnterVehicleHandler() { timerBars.show(true); counter.init(); } mp.events.add('playerEnterVehicle', playerEnterVehicleHandler); I write this code, but it returns me "Cannot read property getSpeed()", what should i do? Edited November 1 by alienwave Share this post Link to post Share on other sites
MrPancakers 108 Posted November 2 (edited) mp.players.local.vehicle doesn't exist until the player is actually sitting down on a seat, that's why you get the error because the event has tried running while you're still trying to sit down. Code is fine, you just can't use just the playerEnterVehicle event, you also need to check if they're in a seat as well before running counter.init() Edited November 2 by MrPancakers Share this post Link to post Share on other sites
alienwave 0 Posted November 2 6 hours ago, MrPancakers said: mp.players.local.vehicle doesn't exist until the player is actually sitting down on a seat, that's why you get the error because the event has tried running while you're still trying to sit down. Code is fine, you just can't use just the playerEnterVehicle event, you also need to check if they're in a seat as well before running counter.init() okey, thank you! Share this post Link to post Share on other sites
Tecidis 0 Posted November 3 Use render event like this mp.events.add('render', () => {if (player.vehicle) { //whatever you want } }); Hope it helped Share this post Link to post Share on other sites
alienwave 0 Posted November 4 22 hours ago, Tecidis said: Use render event like this mp.events.add('render', () => {if (player.vehicle) { //whatever you want } }); Hope it helped lol, thank you, it works. "mp.players.local.vehicle" returns me error, but player.vehicle work fine( Share this post Link to post Share on other sites