Need help figuring out an issue

Found the issue. It apparently was a syntax error. See line 5? I typed else if instead of elseif, cause I come from JavaScript…
Now it works, and even detects when I enter a vehicle, BUT it does not detect when I press L…

Some help would still be highly appreciated! :blush:

Updated code below:

print('Script loaded')
function changeLivery(vehicle) -- Function to change the livery

		print('changeLivery function loaded')
		-- It changes the livery between the first one (0), to the 10th one (9)
		if livery < 9 then -- If the current livery is between 0 and 8 (we are still able to go further)
			livery = livery + 1 -- So we change to the next one
		elseif livery == 9 then -- If the current livery is the last one (9)
			livery = 0 -- Since we can't change to the nexxt one (cause the next is 10, which does not exist), we change it back to 0 (first one)
		end

		SetVehicleLivery(vehicle, livery) -- Native function to set the livery of the vehicle to the above specified livery
		print('Livery should have been changed now')

end

Citizen.CreateThread(function()
	while true do -- Loop that triggers the livery changer function
		print('The script is OK')
		Wait(0)
		ped = GetPlayerPed(-1)

		if IsPedInAnyVehicle(ped, false) then -- Only be able to change the livery if the player is in a vehicle
			print('Vehicle enter event TRIGGERED')
			vehicle = GetVehiclePedIsUsing(ped) -- Get the player vehicle's entity
			livery = GetVehicleLivery(vehicle) -- Current livery

			if IsControlJustPressed(1, 7) then -- If player presses the L key
				print('L key press event TRIGGERED')
				changeLivery(vehicle) -- The livery changer function gets triggered, on the player's vehicle
			end

		end
	end
end)
1 Like

Still super weird that this error doesn’t get catched at the parsing of the scripts, it should say you have a syntax error at line x and col y…

EDIT: Ah found the cause, if it’s a client script, the server will not parse the code, but the client will. So the error was probably in the client log.

Citizen.Trace(“Print Message Here.”)

Yeah I guess it was that. What does Citizen.Trace(“whatever”) do btw?

It’s the print for the client.

Yeah but the normal print seems to work fine on client too.

But the script is still not doing it’s function. It’s supposed to change the livery but it does not detect when I press L… Do you guys know why it is?

Never used it on client. I use trace for client and print for server. That’s just my preference XD. What is not working?

Yeah it’s the same xD.

So, the IsControlPressed(1,7) is not getting triggered. It should trigger whenever I press L, but apparently it doesn’t…

Try IsControlJustPressed(1, 47) – G

1 Like

Citizen.Trace goes to the client console and print goes to the server console?

I don’t know, I just use print on both.

But what is “- G” for? Cause it looks weird…

Open up the console ingame to look for any errors (press F8)

Yeah that’s how I figured it out lol, using the F8 console.

I was just telling you the key was G that’s all.

Oh ok hahaha
I’ll try it

Thanks. It’s working :heart:

I believe the iscontrolpressed is if it’s being held down. But no problem.

I didn’t change that, I just changed the control, it’s still IsControlPressed lol

Apparently SetVehicleLivery(vehicle, livery) is not working for me…