Give gun script will not work

I’ve been trying to fix this for hours. I want the player to be able to use the command /giveweapon which should give them the weapon they ask for. All the prints return the correct thing including the hash, the player ped is valid, everything is correct I’m so confused. Client:

RegisterCommand('giveweapon', function(source, args, rawCommand)
    if #args == 0 then
        TriggerEvent('chat:addMessage', {
            color = {255, 0 , 0},
            args = {'System', 'Usage: /giveweapon [weaponname]'}
        })
        return
    end

    local requestedWeapon = string.lower(args[1])
    print(requestedWeapon)

    TriggerServerEvent('giveweaponServerA', requestedWeapon)
end, false)

Server:

RegisterNetEvent('giveweaponServerA')
AddEventHandler('giveweaponServerA', function(weaponRequest)
    local ped = source
    print("server")
    print(weaponRequest)
    local weaponH = GetHashKey(weaponRequest)
    print(weaponH)

    GiveWeaponToPed(GetPlayerPed(ped), weaponH, 999, false, true)
end)

doesn’t seem to be defined, at least in this chunk of code, however everything else seems to be correct. Do you get any errors in either client or server consoles?

I did not get any errors. I’m very confused as printing weaponH returns the hash key of the pistol.

Try moving the logic to give the weapon to the client side just for a test, I guess, I’m not seeing any reason this shouldn’t work too

I will try that now, thanks for the response. Do you mind giving me advice on how I’ve laid this out please? I’m extremely new to fivem development, having only just started learning yesterday.

Do you mind also briefly explaining the best way to lay out my code? I’m very confused as I had the welcome script from the fivem docs and put it in PlrInit, but it did not work. I moved it to [local] and named it mymode and for some reason it worked? I have no idea what these different folders are for.

Edit: The client code does not work either, no errors, the only output is: “server” “carbinerifle” “557283331”

Client Code:

**RegisterCommand('giveweapon', function(source, args, rawCommand)**
**    if #args == 0 then**
**        TriggerEvent('chat:addMessage', {**
**            color = {255, 0 , 0},**
**            args = {'System', 'Usage: /giveweapon [weaponname]'}**
**        })**
**        return**
**    end**

**    local requestedWeapon = string.lower(args[1])**
**    print(requestedWeapon)**

**    local weaponH = GetHashKey(requestedWeapon)**
**    print(weaponH)**

**    GiveWeaponToPed(GetPlayerPed(ped), weaponH, 999, false, true)**

**    -- TriggerServerEvent('giveweaponServerA', requestedWeapon)**
**end, false)**

Just realized something, are you defining your Lua scripts in the fxmanifest at all? The screenshot shows that they aren’t defined, which means they aren’t read and will not run, obviously. Make sure to have them both in the files table as well as the relevant client_scripts or server_scrips tables

The square bracket [folders] aren’t necessary, you can name them anything you wish or not use them at all - they’re simply there for convenience to “categorize” your resources. Moving stuff from one to another or outside of one has no way to matter in regards to how the code runs.

For the client code, you seem to trying to request GetPlayerPed at ped, however the latter is not defined. Replace it with a PlayerPedId() in the first argument for the native, client-side code and server-side are usually different due to, well, I assume I know why lol

I think I am defining them in fxmanifest properly. I have an fxmanifest script in every folder. The fxmanifest in the weapon script: fx_version ‘cerulean’
game ‘gta5’

client_scripts {
‘client/weaponCommands.lua’
}

server_scripts {
‘server/weapons.lua’
}

Hold up, you can only have one fxmanifest file per resource folder, you can’t “stack” resources one inside another - that’s not how it works. If your PlrInit is a resource, define everything in its fxmanifest and delete any other ones.