Attempt to index a nil value (local 'xplayer')

Hello! I need help with my script (I am new to fivem scripting)
the thing i wanna do is basically just give money to my player but i get error

Server.lua

ESX = nil
local isNear = false

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

RegisterServerEvent('esx_moneygive:money')
AddEventHandler('esx_moneygive:money', function()
    local xPlayer  = ESX.GetPlayerFromId(_source)
    xPlayer.addAccountMoney('bank', 1000)
end)

client.lua

Citizen.CreateThread(function()
	local location = Config.Location
	local ped = GetPlayerPed(PlayerId())
	while true do
		Citizen.Wait(4)
		if isNear then
		Draw3DText(location.x, location.y, location.z, "Press ~y~[E]", 0.4)
			if Vdist(GetEntityCoords(PlayerPedId()),Config.Location) < 1 and IsControlJustReleased(1, 38) then
				TriggerServerEvent('esx_moneygive:money')
			end
		end
	end
end)

Guys i fixed it!! here’s the server.lua

ESX = nil
local isNear = false

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

RegisterNetEvent('esx_moneygive:money')
AddEventHandler('esx_moneygive:money', function()
    local xPlayer = ESX.GetPlayerFromId(source)
    xPlayer.addAccountMoney('bank', 1000)
end)
3 Likes

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