Jump to content

Remove Stat Player With Time


Recommended Posts

Hello, I wrote a resource to change playerstats along with time, but it gives an error
Error details:
gym\server.lua:386:     Bad argument @ 'getPedStat'   [Expected ped at argument 1, got nil]
gym\server.lua:386:    attempt to perform arithmetic on a boolean value

 

function Kamshodan(theplayer)
    setTimer(function()
        setPedStat(thePlayer, 23getPedStat ( thePlayer, 23 ) - 2)
        setPedStat(thePlayer, 22getPedStat ( thePlayer, 22 ) + 2)
       end36001, thePlayer)
    end
 
    addEventHandler ('onResourceStart'getRootElement(), Kamshodan)

 

 

 

can you help me?

Link to comment

Hello, I wrote a resource to change playerstats along with time, but it gives an error
Error details:
gym\server.lua:386:     Bad argument @ 'getPedStat'   [Expected ped at argument 1, got nil]
gym\server.lua:386:    attempt to perform arithmetic on a boolean value

 

function Kamshodan(theplayer)
    setTimer(function()
        setPedStat(thePlayer, 23getPedStat ( thePlayer, 23 ) - 2)
        setPedStat(thePlayer, 22getPedStat ( thePlayer, 22 ) + 2)
       end36001, thePlayer)
    end
 
    addEventHandler ('onResourceStart'getRootElement(), Kamshodan)

 

can you help me?

Link to comment

the player in your code is ambiguous if you want to do it for all players then pull all players with for loop like this

if you're going to do this for a single player it depends on the situation instead you should explain it

function Kamshodan()
    setTimer(
       function()
          for _,player in pairs(getElementsByType("player")) do
             setPedStat(player, 23, getPedStat ( player, 23 ) - 2)
             setPedStat(player, 22, getPedStat ( player, 22 ) + 2)
          end
       end,3600, 1)
    end
addEventHandler ('onResourceStart', getRootElement(), Kamshodan)
Edited by Burak5312
Link to comment

thePlayer is nil and not defined, you’ve wrote “theplayer” 

function Kamshodan(thePlayer)
    setTimer(function()
        if isElement(thePlayer) then -- check if thePlayer is valid
            setPedStat(thePlayer, 23, getPedStat(thePlayer, 23) - 2)
            setPedStat(thePlayer, 22, getPedStat(thePlayer, 22) + 2)
        end
    end, 3600, 1, thePlayer)
end
 
addEventHandler('onResourceStart', getResourceRootElement(getThisResource()), Kamshodan)

 

Link to comment
function Kamshodan()
    setTimer(function()
        for _,thePlayer in ipairs(getElementsByType("player"))do           
            setPedStat(thePlayer, 23, getPedStat(thePlayer, 23) - 2)
            setPedStat(thePlayer, 22, getPedStat(thePlayer, 22) + 2)            
        end
    end,3600,1)
end
addEventHandler('onResourceStart', getResourceRootElement(getThisResource()), Kamshodan)

 

Link to comment
  • Scripting Moderators

Moving this to the scripting section and closing it as OP's issue has been resolved.

LE: Merged the duplicate topic with this one.

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

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