[HELP] Script not working

Hello,

I recently started working on a job system. I was using keyboardInput which @Flatracer gave me. It works perfectly, however I recently was working on a different script, which also uses keyboardInput. Here is the client.lua:

local Job

function KeyboardInput(TextEntry, ExampleText, MaxStringLenght)

    -- TextEntry        -->    The Text above the typing field in the black square
    -- ExampleText        -->    An Example Text, what it should say in the typing field
    -- MaxStringLenght    -->    Maximum String Lenght

    AddTextEntry('FMMC_KEY_TIP1', TextEntry .. ':') --Sets the Text above the typing field in the black square
    DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP1", "", ExampleText, "", "", "", MaxStringLenght) --Actually calls the Keyboard Input
    blockinput = true --Blocks new input while typing if **blockinput** is used

    while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do --While typing is not aborted and not finished, this loop waits
        Citizen.Wait(0)
    end
        
    if UpdateOnscreenKeyboard() ~= 2 then
        local result = GetOnscreenKeyboardResult() --Gets the result of the typing
        Citizen.Wait(500) --Little Time Delay, so the Keyboard won't open again if you press enter to finish the typing
        blockinput = false --This unblocks new Input when typing is done
        return result --Returns the result
    else
        Citizen.Wait(500) --Little Time Delay, so the Keyboard won't open again if you press enter to finish the typing
        blockinput = false --This unblocks new Input when typing is done
        return nil --Returns nil if the typing got aborted
    end
end

RegisterCommand("job", function()
    Job = KeyboardInput("Job:", "", 20)
end, false)

However when I type /job in game it opens up the keyboardInput from my previous script. “Roleplay name:” instead of “Job:”

If anyone could help that would be great,

Thanks,
Scotty

Show us the Serversided Script please

Client.lua:

local Job

Citizen.CreateThread(function ()
	while true do
		Citizen.Wait(10000) 
		TriggerServerEvent('salary')
	end
end)

function KeyboardInput(TextEntry, ExampleText, MaxStringLenght)

    -- TextEntry        -->    The Text above the typing field in the black square
    -- ExampleText        -->    An Example Text, what it should say in the typing field
    -- MaxStringLenght    -->    Maximum String Lenght

    AddTextEntry('FMMC_KEY_TIP1', TextEntry .. ':') --Sets the Text above the typing field in the black square
    DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP1", "", ExampleText, "", "", "", MaxStringLenght) --Actually calls the Keyboard Input
    blockinput = true --Blocks new input while typing if **blockinput** is used

    while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do --While typing is not aborted and not finished, this loop waits
        Citizen.Wait(0)
    end
        
    if UpdateOnscreenKeyboard() ~= 2 then
        local result = GetOnscreenKeyboardResult() --Gets the result of the typing
        Citizen.Wait(500) --Little Time Delay, so the Keyboard won't open again if you press enter to finish the typing
        blockinput = false --This unblocks new Input when typing is done
        return result --Returns the result
    else
        Citizen.Wait(500) --Little Time Delay, so the Keyboard won't open again if you press enter to finish the typing
        blockinput = false --This unblocks new Input when typing is done
        return nil --Returns nil if the typing got aborted
    end
end

RegisterCommand("jobs", function()
    TriggerServerEvent("jobs")
end, false)

RegisterCommand("job", function()
    Job = KeyboardInput("Job:", "", 20)
end, false)

Server.lua:

RegisterNetEvent("jobs")
AddEventHandler("jobs", function(jobs)
    TriggerClientEvent("chatMessage", -1, "JOBS", {255,255,255}, "Current Job: "..Job)
	TriggerClientEvent("chatMessage", -1, "		Other Jobs: Tow | Taxi | Construction")
end)

RegisterServerEvent('salary')
AddEventHandler('salary', function()
  	local salary = 100
	if Job == 'Tow' then
		user.addBank(300)
		notification('Salary Recieved ' .. playerName )
	elseif Job == 'Taxi' then
		user.addBank(200)
		notification('Salary Recieved ' .. playerName )
	elseif Job == 'Construction' then
		user.addBank(100)
		notification('Salary Recieved ' .. playerName )
	else
		notification('The job you entered has not been found.' .. playerName )
    end
end)

function notification(msg)                   
	SetNotificationTextEntry("STRING")
	AddTextComponentString(msg)
	DrawNotification(false, false)
end

Also just to put it out there /jobs does not work either hehe. And I probably did it completely wrong considering how bad I am at life.

If you do manage to see what’s wrong, could you tell me? I want to learn and all that shizzle xd

So, when you enter your job the message, for example, notification('Salary Recieved ' .. playerName ), doesn’t appear?
Edit: Does it add the money to the Bank Account?

If so, that is because you cant use natives serversided, they only work clientsided. So you would have to add a Client Event to draw that message.

1 Like
name = GetPlayerName(PlayerId())
TriggerServerEvent("Example", name)

Something like that would send the playername to the server, then the server would do:

RegisterNetEvent("Example")
AddEventHandler("Example", function(name)
    TriggerClientEvent("chatMessage", -1, "kek",{255,0,0}, "Name: ^2"..name)
end)

therefore name = the players name

1 Like

I’ve got a couple problems, first off when I type /job it shows me this: http://prntscr.com/h4175b (From my other script)

And I cannot do /jobs as when I do it nothing happens.

Also I am not even sure if its giving me the money because I have no money HUD for some reason lol. That’s not related but I am not sure how to check my money. (Using essentialmode).

Use this to get the current bank account balance: user.getBank()

As far as I could (I don’t use ESM), I recreated the script and it worked fine for me.

Hmmm, ok thanks a lot :slight_smile:

The /jobs worked for you?

Yes it did


Hmm wierd. I will try to merge this script with the one I think it might be conflicting with when I get home. Thanks for your help

1 Like

Hmm everything works now except the /jobs command. :confused:

Is Job ~= nil?

I tried it with setting Job to "Testing", then it works

Server.lua

local Job = "Testing"
RegisterNetEvent("jobs")
AddEventHandler("jobs", function(jobs)
    TriggerClientEvent("chatMessage", -1, "JOBS", {255,255,255}, "Current Job: " .. Job)
	TriggerClientEvent("chatMessage", -1, "		Other Jobs: Tow | Taxi | Construction")
end)

Client.lua

RegisterCommand("jobs", function()
    TriggerServerEvent("jobs")
end, false)

Edit: Check if you get any error messages in the RCON Log or the debug log (F8)
Edit 2: An Error like this: attempt to concatenate a nil value (global 'Job')

1 Like

Yeah I managed to fix it with this:

RegisterNetEvent("jobs")
AddEventHandler("jobs", function(Job)
	if Job == nil then
		TriggerClientEvent("chatMessage", -1, "JOBS", {255,255,255}, "Current Job: Nill")
		TriggerClientEvent("chatMessage", -1, "        Other Jobs: Tow | Taxi | Construction")
	else
		TriggerClientEvent("chatMessage", -1, "JOBS", {255,255,255}, "Current Job: "..Job)
		TriggerClientEvent("chatMessage", -1, "        Other Jobs: Tow | Taxi | Construction")
	end
end)
1 Like