Potato_Tomato420 Posted November 25, 2017 Posted November 25, 2017 Can somebody tells me what this error means? Error: SAFshop\speedometer.lua:20 bad argument #1 to 'floor' (number expected, got nil) Script: Spoiler local rx, ry = guiGetScreenSize ( ) function vehiclestatus ( ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if theVehicle and getPedOccupiedVehicleSeat (localPlayer) == 0 then local car = getPedOccupiedVehicle ( localPlayer ) local currentFuel = tonumber(getElementData(car,"fuel")) local x, y, z = getElementPosition( localPlayer ) local sx, sy, sz = getElementVelocity ( car ) local kphSpeed = math.ceil( ( ( sx^2 + sy^2 + sz^2 ) ^ ( 0.5 ) ) * 161 ) local mphSpeed = math.ceil( ( ( ( sx^2 + sy^2 + sz^2 ) ^ ( 0.5 ) ) * 161 ) / 1.61 ) local health = getElementHealth ( car ) local name = getVehicleName ( car ) local currenthealth = math.floor( health/10 ) -- dxDraw -- dxDrawRectangle( ( rx-205 ), ( ry-78 ), 199, 17, tocolor(0, 0, 0, 180), true) dxDrawRectangle( ( rx-205 ), ( ry-54 ), 199, 17, tocolor(0, 0, 0, 180), true) dxDrawRectangle( ( rx-205 ), ( ry-30 ), 199, 17, tocolor(0, 0, 0, 180), true) dxDrawText ( "Speed: "..tostring(kphSpeed).." KM/H", ( rx - 199 ), ( ry - 77 ), 1280, 887, tocolor ( 255, 255, 255, 255 ), 1,"default-bold", "left", "top", false, false, true, true, false ) dxDrawText ( "Vehicle: "..tostring(currenthealth).."% | Fuel: " .. math.floor(currentFuel) .. "%", ( rx - 199 ), ( ry - 53 ), 1280, 887, tocolor ( 255, 255, 255, 255 ), 1,"default-bold", "left", "top", false, false, true, true, false ) dxDrawText ( "Location: " .. getZoneName(x, y, z), (rx - 199 ), ( ry - 29), 1280, 887, tocolor ( 255, 255, 255, 255 ), 1, "default-bold", "left", "top", false, false, true, true, false ) end end addEventHandler ( "onClientRender", root, vehiclestatus )
Scripting Moderators thisdp Posted November 25, 2017 Scripting Moderators Posted November 25, 2017 Error: SAFshop\speedometer.lua:20 bad argument 'math.floor' at argument 1 (number expected, got nil) Now can you understand it?
Potato_Tomato420 Posted November 25, 2017 Author Posted November 25, 2017 Yes now i know what the error means But still don't understand why it has no number. This is a function of a other script (same resource): Spoiler function setFuel(player,seat,jacked,vehicle) if(getElementData(source,"fuel") == false) then fuel = math.random(70,100) setElementData(source,"fuel",tonumber(fuel)) end end addEventHandler("onClientVehicleEnter",getRootElement(),setFuel)
Scripting Moderators thisdp Posted November 25, 2017 Scripting Moderators Posted November 25, 2017 (edited) It means you pass a nil value into the function math.floor as its first argument. Edited November 25, 2017 by thisdp
Miika Posted November 25, 2017 Posted November 25, 2017 It means you haven’t set a value to currentFuel
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now