So i need some help with this script im working on with ui so when you hit the readbutton it should check and see if the player has the item called credit card and if they do it will print random vaules inside of the textarea track1,2 and if you dont have the item called credit card it will display an error in track1 and track2. this is my code and it doesn’t work can someone help me out.
Here is my server.lua
`RegisterNUICallback("readbutton", function(data, callback)
local hasCreditCard = exports.ox_inventory:Search(source, 'count', 'scamming_creditcard')
if hasCreditCard > 0 then
-- Trigger client-side event to generate credit card values
TriggerClientEvent("generateCreditCardValues", source)
lib.notify({
title = 'Scamming',
description = 'You swiped a credit card.',
type = 'success'
})
TriggerServerEvent("flow_scamming:remove_creditcard")
TriggerServerEvent("flow_scamming:give_creditcard_details")
lib.notify({
title = 'Scamming',
description = 'You now have the card\'s details.',
type = 'success'
})
else
lib.notify({
title = 'Scamming',
description = 'You do not have a credit card.',
type = 'error'
})
local response = { error = 'You do not have a credit card.' }
callback(response)
end
end)
``
here is my client.lua
RegisterNetEvent("generateCreditCardValues")
AddEventHandler("generateCreditCardValues", function()
TriggerEvent('chat:addMessage', {
args = {"^*^5Scamming", "You now have the card's details."}
})
SendNUIMessage({
action = "generateCreditCardValues"
})
end)
here is my js
function generateCreditCardValues() {
var cardNumber = generateRandomDigits(16);
var expirationDate = generateRandomExpirationDate();
var fullName = generateRandomName();
var cvv = generateRandomDigits(3);
var track1Value = 'B' + cardNumber + '^' + fullName + '^' + expirationDate + '00045212000';
var track2Value = cardNumber + '=' + expirationDate.replace('/', '') + cvv;
document.getElementById('track1').value = track1Value;
document.getElementById('track2').value = track2Value;
}
function generateRandomDigits(length) {
var digits = '';
for (var i = 0; i < length; i++) {
digits += Math.floor(Math.random() * 10);
}
return digits;
}
function generateRandomExpirationDate() {
var expirationMonth = ('0' + (Math.floor(Math.random() * 12) + 1)).slice(-2);
var expirationYear = String(new Date().getFullYear() + Math.floor(Math.random() * 10)).slice(-2);
return expirationMonth + '/' + expirationYear;
}
function generateRandomName() {
var firstNames = ['Elvis', 'Jane', 'Alice', 'Bob', 'Charlie'];
var lastNames = ['Presley', 'Johnson', 'Williams', 'Jones', 'Brown'];
var firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
var lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
return firstName + ' ' + lastName;
}
here is the html
<legend style="display: flex; width: 90%; justify-content: space-between;">
<div>
<input type="checkbox" id="check_track1"> <label for="check_track1"> Track1 210 BP1 7
BPC
Odd Parity </label>
</div>
<span style="margin-left: auto;">0</span>
</legend>
<div class="checkbox-group">
<div class="field-row-stacked">
<textarea id="track1" rows="8"></textarea>
</div>
</div>
</fieldset>
<fieldset>
<legend style="display: flex; width: 90%; justify-content: space-between;">
<div>
<input type="checkbox" id="check_track2"> <label for="check_track2"> Track2 75 BP1 5
BPC
Odd Parity </label>
</div>
<span style="margin-left: auto;">0</span>
</legend>
<div class="checkbox-group">
<div class="field-row-stacked">
<textarea id="track2" rows="8"></textarea>
</div>
If anyone can help me with this would be helpful