This functions constantly loops through all players every frame, which is extremly excessive.
You could limit the looping to every 500 ms like this:
local lastDataSet = 0
local dataSetCooldown = 500 -- in ms
exports.scoreboard:scoreboardAddColumn( "Wanted", 45 )
exports.scoreboard:scoreboardAddColumn( "Money", 55 )
function ScoreBoardWanted(thePlayer)
-- if getTickCount is smaller than the last time we set the elementdata, return false, else loop through all players and set the cooldown
if ( getTickCount( ) < lastDataSet + dataSetCooldown ) then
return false
end
for _,player in ipairs( getElementsByType("player") ) do
setElementData ( player, "Wanted", getPlayerWantedLevel ( ) )
setElementData ( player, "Money", getPlayerMoney ( ) )
end
lastDataSet = getTickCount( )
end