Jump to content

help please im getting errors


Recommended Posts

i want to get $100 every 5 mins it saying lots of error dont know why

 function giveMoney(source) 
            givePlayerMoney ( thePlayer, 1000 ) 
setTimer ( giveMoney, 5000, 0 ) 
    local money = getPlayerMoney(source) 
if (money > 6000) then 
resetTimer ( giveMoney ) 
addEventHandler ( "onPlayerSpawn", getRootElement(), giveMoney ) 

Link to comment

Because you make the giveMoney function create an infinite timer which calls giveMoney itself. That means, every time a new timer is created. If only want one repeating cycle, either create the timer in another function and attach that function to "onPlayerSpawn" event or simple change the third setTimer argument to 1.

Link to comment
Okay lemme check
function kay (thePlayer) 
 givePlayerMoney (thePlayer, 100) 
  setTimer(kay, 300000, 1) 
addEventHandler ("onPlayerSpawn", root, kay) 

Try this, untested

Again, there's no player parameter.

It's source and it's not sent in parameters of function.

function kay (source)

givePlayerMoney (source, 100)

setTimer(kay, 300000, 1)


addEventHandler ("onPlayerSpawn", root, kay)

got errors line 2

If you would have read what I said, you would not get them but you seem like you just want to copy code.

Link to comment

If I'm right, it's inefficient to use one timer for each player, and it's more efficient to loop all players with one timer.

setTimer ( 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            givePlayerMoney ( player, 100 ) 
    ,300000, 0 

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