Hzarein56 Posted June 23, 2023 Share Posted June 23, 2023 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, 23, getPedStat ( thePlayer, 23 ) - 2) setPedStat(thePlayer, 22, getPedStat ( thePlayer, 22 ) + 2) end, 3600, 1, thePlayer) end addEventHandler ('onResourceStart', getRootElement(), Kamshodan) can you help me? Link to comment
Hzarein56 Posted June 23, 2023 Author Share Posted June 23, 2023 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, 23, getPedStat ( thePlayer, 23 ) - 2) setPedStat(thePlayer, 22, getPedStat ( thePlayer, 22 ) + 2) end, 3600, 1, thePlayer) end addEventHandler ('onResourceStart', getRootElement(), Kamshodan) can you help me? Link to comment
βurak Posted June 23, 2023 Share Posted June 23, 2023 (edited) 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 June 23, 2023 by Burak5312 Link to comment
Hzarein56 Posted June 23, 2023 Author Share Posted June 23, 2023 Thank you for your help @Burak5312 Link to comment
βurak Posted June 23, 2023 Share Posted June 23, 2023 (edited) You're welcome. If you have any other questions, open a topic, I'll help as much as I can. Edited June 23, 2023 by Burak5312 Link to comment
FLUSHBICEPS Posted June 23, 2023 Share Posted June 23, 2023 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
_SAXI_ Posted June 24, 2023 Share Posted June 24, 2023 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
Moderators Vinyard Posted June 24, 2023 Moderators Share Posted June 24, 2023 (edited) 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 June 24, 2023 by Vinyard Link to comment
Recommended Posts