Jump to content

Server variables to client returns undefined


Recommended Posts

Hello! I'm creating a vehicle system and I'm adding a fuel system.

In serverside i got this:

// The chat says that fuel is 80, THIS IS CORRECT, when I create the vehicle I give 80 of fuel.

function playerEnterVehicleHandler(player, vehicle, seat) {
	player.outputChatBox(`${player.name} got into the car with ID: ${vehicle.id}. Seat: ${seat}. Fuel: ${vehicle.fuel}`);
	if(seat == -1)
		if(vehicle.fuel === 0)
			player.outputChatBox("Vehicle Tank is empty.");
			vehicle.engine = false;

But when I try to get the variable from client it says "undefined":

// The output says: (example) Speed: 120, gear: 4, RPM: 4.44..., Fuel: undefined

mp.events.add("render", () => {
	var player = mp.players.local;
	if (player.vehicle && player.vehicle.getPedInSeat(-1)) {
		var veh = player.vehicle;
		var rpm = player.vehicle.rpm;
		var gear = player.vehicle.gear;
		var fuel = player.vehicle.fuel;
		if(velocimetro) {
			mp.gui.chat.push("Speed: "+veh.getSpeed()", gear: "+gear+", RPM: "+rpm+", Fuel: "+fuel);

Anyone? Thanks in advice!

Link to comment
Share on other sites

Simply adding a property onto an object doesn't instantly make it synced to the client.

In order to do this you either need to use "entity.data.fuel" or "entity.setVariable('fuel', value);" and clientside you'd use "entity.getVariable('fuel');"




  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...