Recently I have tried to make more complicated weapons as I have only done simple things before this. I have a machine gun that I want to slow down the player while it is equipped. So during the deploy and holster functions I have it set another function to true or false (which this function controls the playerspeed). I feel like this is overly complicated. I have tried to use :setwalkspeed(x) during the deploy and holster functions but I get errors complaining that “self” or “self.owner” or “ply” or “whatever i put in front of :setwalkspeed” is not a global variable…which I don’t see why that matters. As of now the code runs with no errors but does nothing for this section.
Anyways all I’m asking is how to fix this code. Or make code that does the same function in a more simplistic way.
function SWEP:Deploy() self.Owner.movedeployspeed = true return true end function SWEP:Holster() self.Owner.movedeployspeed = false return true end local function deployspeed() if ent.movedeployspeed and ent:IsPlayer() then self:SetWalkSpeed(45) end end hook.Add("Deploy", "deployspeed", deployspeed)
I don’t even fully understand this code I’ve written as alot of this is based on what I’ve either experimented with or what I just guessed by seeing it on the Wiki. I have searched all the setwalkspeed/runspeed posts and looked on Google and examined other lua code and I cannot find any solution. I think my problem is with the “hook.Add”.