Jump to content

(fixed) Updating ScoreBoard Text does not work (setElementDa


BlueTheFurry

Recommended Posts

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:

2ccba6c2fc.PNG

Greetings!

Edited by Guest
Link to comment
  
  
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

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

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...