Jump to content

Problem [getElementData]


rublisk19

Recommended Posts

function expcalculate ( source, command ) 
      setElementData(source, "EXP",tonumber(getElementData(source, "EXP"))+1) 
end 
setTimer(expcalculate, 20000,0) 

I get error :?: : Bad argument @ 'getElementData' [Expected element ar argument 1, got nil]

attempt to perform arithmetic on a nil value

If you can pls fix this script to make working ;] . I need this to get exp every 20sec!!

Link to comment

"source" is an invalid element type, because it's only used for event handlers.

Just use your mind a bit, and think: "where the hell did I get source from?".

So, if this is a client script, you could replace source by getLocalPlayer ( ), or a predefined player variable being called from getLocalPlayer ( ).

local player = getLocalPlayer ( ) 
  
function expcalculate ( ) 
      setElementData ( player, "EXP", tonumber ( getElementData ( player, "EXP" ) ) +1, true ) 
end 
setTimer ( expcalculate, 20000, 0 ) 

This will set player's EXP data to both server and client-side, you can call that element data from any side.

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...