Skip to Content
SnippetsLua Snippets

Lua Snippets

Common Lua patterns for FiveM resources.

Server: Get Player

-- QBCore local Player = QBCore.Functions.GetPlayer(source) -- ESX local xPlayer = ESX.GetPlayerFromId(source)

Server: Add Money

-- QBCore Player.Functions.AddMoney('cash', 100) -- ESX xPlayer.addMoney(100)

Client: Show Notification

-- Using ox_lib lib.notify({ title = 'Server', description = 'Message here', type = 'success' })

Client: Thread with Wait

CreateThread(function() while true do Wait(1000) -- Do something end end)

Debounced Event

local lastTime = 0 RegisterNetEvent('myresource:action') AddEventHandler('myresource:action', function() local now = GetGameTimer() if now - lastTime < 1000 then return end lastTime = now -- Do action end)
Last updated on