Why does this Lua not Work

This code doesent work…

ESX = nil

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


function Steuern()
	local _source = source

    local xPlayer = ESX.GetplayerFromId(_source)

    local StAmount = config.Steuern

    xPlayer.removeAccountMoney('bank', Config.Steuern )
    TriggerEvent("grv_notify", "#ab0503", "STEUERN", "Du Hast deine Steuern Bezahlt!:", StAmount)
    wait(config.SeuerIntervall)
end

RegisterCommand("steuern", function()
	print("Test Erfolgreich!")
end)   

RegisterCommand("dodo", function()
	TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)
	local xTarget = ESX.GetPlayerFromId(playerId)
    print("passed lines 3&4")
	xPlayer.removeAccountMoney('bank', Config.Steuern)
	print("Passed lines 4&5")
	Print("Youre paid ")
end)

Please help.
It comes: xPlayer dont found

You need to pass source to that function because it is nil.

ESX = Steuern()

You mean so?

function Steuern(source) --here
	local _source = source

    local xPlayer = ESX.GetplayerFromId(_source)

    local StAmount = config.Steuern

    xPlayer.removeAccountMoney('bank', Config.Steuern )
    TriggerEvent("grv_notify", "#ab0503", "STEUERN", "Du Hast deine Steuern Bezahlt!:", StAmount)
    wait(config.SeuerIntervall)
end

And then in the in the place where you fire this function to pass it.

From what I remember you need to add source and args as variable in RegisterCommand function. Then for the target id you need to use args[1] but thats not all. Args[1] is a string ESX.GetPlayerFromId requires number so you need to pass tonumber(args[1]) . BTW you don’t need to get esx again while doing that command

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