jamesRL Posted November 20, 2022 Share Posted November 20, 2022 Hi, I can't seem to trigger server event. Chat(), SetDisplay(), print works but not the trigger. What can I do? New to FiveM dev btw. JS: $("#submit").click(function () { let IDinputValue = $("#IDinput").val() let AmountinputValue = $("#Amountinput").val() if (IDinputValue.length >= 100) { $.post("http://nui2/error", JSON.stringify({ error: "Input was greater than 100" })) return } else if (!IDinputValue) { $.post("http://nui2/error", JSON.stringify({ error: "There was no value in the input field" })) return } // if there are no errors from above, we can send the data back to the original callback and hanndle it from there $.post('http://nui2/main', JSON.stringify({ PlayerID: IDinputValue, Amount: AmountinputValue, })); return; }) Client side: (here I call the TriggerServerEvent) RegisterNUICallback("main", function(data) chat(data.PlayerID, {0,255,0}) SetDisplay(false) print("test") TriggerServerEvent('qb-faktura:server:payfaktura', source, data.PlayerID, data.Amount) end) Server side: (Here I register the ServerEvent) local QBCore = exports['qb-core']:GetCoreObject() RegisterNetEvent('qb-faktura:server:payfaktura', function(source, id, amount) local src = source local Player = QBCore.Functions.GetPlayer(src) if Player.PlayerData.money.bank >= amount then Player.Functions.RemoveMoney('bank', amount , "fakturabetaling") --id.Functions.AddMoney('bank',amount, "fakturabetaling") TriggerClientEvent('QBCore:Notify', src, "Du betalte " ..amount.. " kr til " .. id , "success") else TriggerClientEvent('QBCore:Notify', src, "Du har ikke nok penger", "error") end end) Anyone who knows? local QBCore = exports['qb-core']:GetCoreObject() RegisterNetEvent('qb-faktura:server:payfaktura') AddEventHandler('qb-faktura:server:payfaktura', function(id, amount) local src = source local Player = QBCore.Functions.GetPlayer(src) id = tonumber(id) amount = tonumber(amount) if Player.PlayerData.money.bank >= amount then Player.Functions.RemoveMoney('bank', amount , "fakturabetaling") --id.Functions.AddMoney('bank',amount, "fakturabetaling") TriggerClientEvent('QBCore:Notify', src, "Du betalte " ..amount.. " kr til " .. ID , "success") else TriggerClientEvent('QBCore:Notify', src, "Du har ikke nok penger", "error") end end) Fixed it. Easy fix. just handle as number and not string. Link to comment
jamesRL Posted November 20, 2022 Author Share Posted November 20, 2022 I got now another error in console. attempt to concatenate a nil value (local 'id'). Local ID seems to not being used, and the amount value passed from client side is now the same value as the ID? What is wrong here? Link to comment
Spakye Posted November 21, 2022 Share Posted November 21, 2022 Hello, you are on the wrong forum im afraid. This forum is about Mta sa which is a mod to play san andreas online. Nothing to do with fiveM 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now