Jump to content

[HELP] Little help please , its simple but i couldn't.


yusufbali

Recommended Posts

Please help me, i try but i can't fix this. Im newbie

client.lua:16: Bad argument @'setElementData'[Expected element at agument 1,got nil]

  
function getPlayerFromPartialName(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function siramiayarla(name, i) 
local player = getPlayerFromPartialName(name) 
setElementData(player,"Sıra",i) 
end 
addEvent("siraayarla", true) 
addEventHandler("siraayarla", root, siramiayarla) 

Link to comment

Replace the function with this:

function siramiayarla(name, i) 
local player = getPlayerFromPartialName(name) 
if not player then outputChatBox ( "Player not found. Name" ..name.. "/ i: "..i )  
else 
outputChatBox("player found")  
end 
setElementData(player,"Sıra",i) 
end 

After running the code let me know what it outputs.

Link to comment
Can we see when do you trigger the server event?

I'm just thinking you probably are putting in a player element which causes a error either the player never is there by that partial name.

function createTopSystem( player ) 
    if not isElement( player ) then 
        return 
    end 
    local Top = {} 
    local CreatTop = executeSQLQuery( "SELECT * FROM stats6" ) 
    for i = 1, #CreatTop do 
        table.insert(Top,{nickim = CreatTop[i].nickim,puan = CreatTop[i].puan}) 
    end 
    if #CreatTop >0 then 
        table.sort(Top, function(a,b) return (tonumber(a.puan)or 0) > (tonumber(b.puan)or 0) end) 
    setTimer( 
    function() 
        for k, data in ipairs(Top) do 
            triggerClientEvent (player,"siraayarla",player,tostring(data.nickim),tonumber(k)) 
        end 
    end, 
        50, 
    1 
    ) 
    end 
end 

Replace the function with this:
function siramiayarla(name, i) 
local player = getPlayerFromPartialName(name) 
if not player then outputChatBox ( "Player not found. Name" ..name.. "/ i: "..i )  
else 
outputChatBox("player found")  
end 
setElementData(player,"Sıra",i) 
end 

After running the code let me know what it outputs.

Same warning,

@1 player found

@2 player not found . NameCrysler /i:2

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