How would I set walkspeed when player equips a gun?

I have been looking around with google trying to find a way to make the player equipped with the swep to change it’s walk speed so far the examples I have seen have not worked. For example lets say If i wanted to make the holder of this pistol the speed of 999 how would I do this properly and when the player changes to another weapon I would want their walk speed to change back to normal. Could someone point me to the right direction I know the WalkSpeed function would be involved for this.

I don’t want the players walk speed to change as soon as the player fires the weapon I want it to happen when the player equips the gun.*

if SERVER then
AddCSLuaFile( “shared.lua” )

SWEP.HoldType = “pistol”

if CLIENT then
SWEP.PrintName = “pistol_name”
SWEP.Slot = 1

SWEP.Icon = “VGUI/ttt/icon_pistol”


SWEP.Base = “weapon_tttbase”
SWEP.Primary.Recoil = 1.5
SWEP.Primary.Damage = 25
SWEP.Primary.Delay = 0.38
SWEP.Primary.Cone = 0.02
SWEP.Primary.ClipSize = 20
SWEP.Primary.Automatic = true
SWEP.Primary.DefaultClip = 20
SWEP.Primary.ClipMax = 60
SWEP.Primary.Ammo = “Pistol”
SWEP.AutoSpawnable = true
SWEP.AmmoEnt = “item_ammo_pistol_ttt”

SWEP.ViewModel = “models/weapons/v_pist_fiveseven.mdl”
SWEP.WorldModel = “models/weapons/w_pist_fiveseven.mdl”

SWEP.Primary.Sound = Sound( “Weapon_FiveSeven.Single” )
SWEP.IronSightsPos = Vector( 4.53, -4, 3.2 )

Do not know I would have tried.

function SWEP: Think ()
if self.Owner: GetActiveWeapon () == self then self.Owner: SetWalkSpeed ​​(999) end

May not know is wrong)

Yea but then if you un-equip it, won’t your speed still be 999?

It works!

Thank you!