Help with addmoney

I’ve been trying to make an event that gives you a random amont of money 3500, 5000 as item, but is not working, when i TriggerEvent(gogoto:rewarditem) nothing happens

QBCore = exports['qb-core']:GetCoreObject()

RegisterNetEvent('gogoto:rewarditem')
AddEventHandler('gogoto:rewarditem', function(listKey)
    local src = source 
    local Player = QBCore.Functions.GetPlayer(src)
    local item = Config.Items
            Player.Functions.AddMoney(item, math.random(3500, 5000))
            TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
end)

Config

Config = {}

Config.Items = {
    "cash",
}

Hello PDF,

where do you execute your TriggerEvent('gogoto:rewarditem') on client or serverside? Have you ever debugged your code to find out if the problem is in the event code or the event’s call?

Remember:

On clientside it should be:

TriggerServerEvent('gogoto:rewarditem')

On serverside it should be:

TriggerEvent('gogoto:rewarditem')

You can make this a lot easier by doing this

Player.Functions.AddMoney('cash', math.random(3500, 5000)) -- Just make it cash

If you want the config to work you can do this

Config = {}

Config.Items = {
    "cash",
}

Then in client you can do

QBCore = exports['qb-core']:GetCoreObject()

RegisterNetEvent('gogoto:rewarditem')
AddEventHandler('gogoto:rewarditem', function()
    local src = source 
    local Player = QBCore.Functions.GetPlayer(src)
    
    -- Selecting the first array in the Config
    local item = Config.Items[1]
    
    if item then
        local cashAmount = math.random(3500, 5000)
        Player.Functions.AddMoney(item, cashAmount)
        TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
    end
end)

If you want the money to be bank you can use this

Config = {}

Config.Items = {
    "cash",
    "bank"
}

Then in your client you can do this

QBCore = exports['qb-core']:GetCoreObject()

RegisterNetEvent('gogoto:rewarditem')
AddEventHandler('gogoto:rewarditem', function()
    local src = source 
    local Player = QBCore.Functions.GetPlayer(src)
    
    -- Selecting the second array in the Config since bank is the second array
    local item = Config.Items[2]
    
    if item then
        local cashAmount = math.random(3500, 5000)
        Player.Functions.AddMoney(item, cashAmount)
        TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
    end
end)

Let me know if this helps : )

Yes, you’re true, i was missing that and some things from server.lua thanks

Yes, that solved my server.lua issue, thank you :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.