BlueTheFurry Posted February 12, 2015 Share Posted February 12, 2015 (edited) Old Post ___________________________________________ Hello community, i am back with another problem, i was trying to make a level for a Drift score on my server wich will be shown on the scoreboard, everything works fine, no errors, it just does not update the elementData: (function is triggered, i tested it by the "outputChatBox" function ) function updatelvl() local players = getElementsByType ( "player" ) outputChatBox("got elements by type") for theKey,thePlayer in ipairs(players) do outputChatBox("did it") totaldrift = getElementData(thePlayer, "Total Drift" ) if tostring(totaldrift) < "99000" then setElementData(thePlayer, "Drift Rank", "Newbie" ) elseif tostring(totaldrift) > "100000" then setElementData(thePlayer, "Drift Rank", "Trained" ) elseif tostring(totaldrift) > "500000" then setElementData(thePlayer, "Drift Rank", "Drifter" ) elseif tostring(totaldrift) > "1000000" then setElementData(thePlayer, "Drift Rank", "Adv. Drifter" ) elseif tostring(totaldrift) > "5000000" then setElementData(thePlayer, "Drift Rank", "Best Drifter" ) elseif tostring(totaldrift) > "25000000" then setElementData(thePlayer, "Drift Rank", "Drift King" ) elseif tostring(totaldrift) > "50000000" then setElementData(thePlayer, "Drift Rank", "Drift Expert" ) elseif tostring(totaldrift) > "100000000" then setElementData(thePlayer, "Drift Rank", "Drift Master" ) elseif tostring(totaldrift) > "500000000" then setElementData(thePlayer, "Drift Rank", "Drift Elite" ) end end end addEvent("updatelvl", true ) addEventHandler("updatelvl", getRootElement(), updatelvl ) scoreboard: Greetings! Edited February 13, 2015 by Guest Link to comment
Tomas Posted February 12, 2015 Share Posted February 12, 2015 function updatelvl() local players = getElementsByType ( "player" ) outputChatBox("got elements by type") for theKey,thePlayer in ipairs(players) do outputChatBox("did it") totaldrift = getElementData(thePlayer, "Total Drift" ) if totaldrift < 99000 then setElementData(thePlayer, "Drift Rank", "Newbie" ) elseif totaldrift > 100000 then setElementData(thePlayer, "Drift Rank", "Trained" ) elseif totaldrift > 500000 then setElementData(thePlayer, "Drift Rank", "Drifter" ) elseif totaldrift > 1000000 then setElementData(thePlayer, "Drift Rank", "Adv. Drifter" ) elseif totaldrift > 5000000 then setElementData(thePlayer, "Drift Rank", "Best Drifter" ) elseif totaldrift > 25000000 then setElementData(thePlayer, "Drift Rank", "Drift King" ) elseif totaldrift > 50000000 then setElementData(thePlayer, "Drift Rank", "Drift Expert" ) elseif totaldrift > 100000000 then setElementData(thePlayer, "Drift Rank", "Drift Master" ) elseif totaldrif) > 500000000 then setElementData(thePlayer, "Drift Rank", "Drift Elite" ) end end end addEvent("updatelvl", true ) addEventHandler("updatelvl", getRootElement(), updatelvl ) Link to comment
JR10 Posted February 12, 2015 Share Posted February 12, 2015 You might still be comparing a string to a number, you need to use tonumber to make sure that the compared object is a number. function updatelvl() local players = getElementsByType ( "player" ) outputChatBox("got elements by type") for theKey,thePlayer in ipairs(players) do outputChatBox("did it") totaldrift = tonumber(getElementData(thePlayer, "Total Drift" )) or 0 if totaldrift < 99000 then setElementData(thePlayer, "Drift Rank", "Newbie" ) elseif totaldrift > 100000 then setElementData(thePlayer, "Drift Rank", "Trained" ) elseif totaldrift > 500000 then setElementData(thePlayer, "Drift Rank", "Drifter" ) elseif totaldrift > 1000000 then setElementData(thePlayer, "Drift Rank", "Adv. Drifter" ) elseif totaldrift > 5000000 then setElementData(thePlayer, "Drift Rank", "Best Drifter" ) elseif totaldrift > 25000000 then setElementData(thePlayer, "Drift Rank", "Drift King" ) elseif totaldrift > 50000000 then setElementData(thePlayer, "Drift Rank", "Drift Expert" ) elseif totaldrift > 100000000 then setElementData(thePlayer, "Drift Rank", "Drift Master" ) elseif totaldrif) > 500000000 then setElementData(thePlayer, "Drift Rank", "Drift Elite" ) end end end addEvent("updatelvl", true ) addEventHandler("updatelvl", getRootElement(), updatelvl ) Link to comment
BlueTheFurry Posted February 13, 2015 Author Share Posted February 13, 2015 You might still be comparing a string to a number, you need to use tonumber to make sure that the compared object is a number. [/lua] Thanks, that worked! Link to comment
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