Need help for give a swep

I make a script for creating a weapon: a gun license!
All is good, the swep a spawnable in the windows “weapons/Other”, but I want this swep is automatically given when a player get a license by a mayor or by a job. And I won’t, the gun license weapon is stripped when the mayor revoked the license!

So I write this and i put this in : /garrysmod/addons/MyAddons/lua/autorun/server/sv_givelisence.lua


function GiveLisence( ply )
	if hasLicense == true then
		ply:Give("gunlisence")
	else if hasLicense == false then
		ply:StripWeapon("gunlisence")
		end
	end
	
end

And the sweep doesn’t have problems, but she has not given when we do /givelisence :confused:

Did my ideas are possibles ?
Could you help me ?

Where do you set hasLicense?

I don’t set this variable and I’m not sure she is really functional… :weeb:
I’m have to set the variable or there is one define ?

I found this but i’m not sure


if LocalPlayer():getDarkRPVar("HasGunlicense") then

So I make this



local function GiveLisence( ply )
	if LocalPlayer():getDarkRPVar("HasGunlicense") then
		ply:Give("gunlisence")
	else
		ply:StripWeapon("gunlisence")
	
	end
end

function GiveLisence()

But not working again… I think, i put it in the bad folder :confused:

Up ?!? Nobody now how to do this ?

Can you show us your code? Because i don’t know what are you trying to do with that function GiveLisence() after you defined it in a local enviroment

Have you made the SWEP yet?

Yes i made the swep who called : “gunlisence”. It is textured and functionnal but i wan’t to give it when somebody got a gun license…

I don’t now how to call the function and where, that’s why I need help…

It looks like you’ve already got a half decent understanding of what you’re doing, so you’ll probably learn best if I just drop you some code



function SWEP:PrimaryAttack()
    if not self:CanPrimaryAttack() then return end
    if not IsValid( self:GetOwner() ) then return end
    
    local ply = self:GetOwner()
    local trace = ply:GetEyeTrace()
    local target = trace.Entity
    
    if not IsValid( target ) then return end
    if not target:IsPlayer() then return end
    
    GiveLisence( ply )
    
    self:SetNextPrimaryFire( CurTime() + 1 )
end


Untested, but it should work. If you have any problems, you can add me on Steam using the icon below my name, good luck!