First make this at the start of your code:
local carbine = false
Then change your 2 events into this one event:
RegisterNetEvent("UnlockCarbine")
AddEventHandler("UnlockCarbine", function()
local weapon = GetHashKey("WEAPON_CARBINERIFLE")
local ped = GetPlayerPed(PlayerId())
carbine = not carbine
if carbine then
GiveWeaponToPed(ped, weapon, 1000, false, true)
else
RemoveWeaponFromPed(ped, weapon)
end
end)
That should work, have not tested it though.