• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Bug in reward tfs 1.2

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi my dear friends,

I'm trying to create a reward system and I'm getting a problem to give the reward.

On lib.lua
Code:
local config = {
    rewards = {  
        {itemId = 9074, count = 1},
        {itemId = 2157, count = 1},
        {itemId = 18423, count = 1},
    }
}

function reward.addReward(self, playerId)
    local reward = math.random(#config.rewards)
    if not reward then
        return
    end
  
    local player = Player(playerId)
    if not player or not player:addItem(reward.itemId, reward.count) then
        return
    end
end

actions
Code:
reward:addReward(player)

And the error that I'm getting is
data/lib/core/reward.lua:16: attempt to index local 'reward' (a number value)

Can someone help me on that?

Thanks.
 
local reward = math.random(#config.rewards)

reward will hold the return value from math.random(a number).
you forget to get the real table, something like this:

local reward = config.rewards[math.random(#config.rewards)]
 

Similar threads

Back
Top