• SWEP Timer.Create Problems
    5 replies, posted
Hello! This is the second time that I have used the forums today but I need more help with my SWEP. Basically, I create a timer because I want it to return the speed of the player to the same value but it keeps giving me the error of 'bad argument #4 to 'Create' (function expected, got no value)' I will send the lines of code and then the whole thing. Thanks! {if (Number > 1.99 and Number < 3 ) then timer.Create( "OriginalJump" , 5 , 0 , function() self.Owner:SetJumpPower( 200 )  ) UpLaunchPly( self.Owner ) end} {if (Number > 2.99 and Number < 4) then timer.Create( "OriginalSpeed", 5 , 0 , function() self.Owner:SetRunSpeed( 320 ) ) SpeedPly(self.Owner) end} And the whole code: { local function LaunchPly( ply ) ply:SetVelocity( ply:GetAimVector() * 6000 ) end local function SpeedPly( ply ) ply:SetRunSpeed( 500 ) end local function UpLaunchPly( ply ) ply:SetJumpPower( 1000 ) end  SWEP.PrintName = "Random Gun" SWEP.Author = "DramaLlama" SWEP.Contact = "PlaceHolder" SWEP.Instructions = "Click and see what happens" SWEP.Category = "Random Gun" SWEP.Spawnable= true SWEP.AdminSpawnable= true SWEP.AdminOnly = false SWEP.ViewModelFOV = 70 SWEP.ViewModel = "models/weapons/v_Pistol.mdl"  SWEP.WorldModel = "models/weapons/v_Pistol.mdl" SWEP.ViewModelFlip = false SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Slot = 2 SWEP.SlotPos = 1 SWEP.UseHands = false SWEP.HoldType = "Pistol"  SWEP.FiresUnderwater = false SWEP.DrawCrosshair = true SWEP.DrawAmmo = false SWEP.ReloadSound = "Weapon_Pistol.Reload" SWEP.Base = "weapon_base" SWEP.Primary.Sound = Sound("Weapon_Pistol.Single")  SWEP.Primary.Damage = 0 SWEP.Primary.TakeAmmo = 2 SWEP.Primary.ClipSize = 5 SWEP.Primary.Ammo = "Pistol" SWEP.Primary.DefaultClip = 5 SWEP.Primary.Spread = 0.25 SWEP.Primary.NumberofShots = 1 SWEP.Primary.Automatic = false SWEP.Primary.Recoil = 0.20 SWEP.Primary.Delay = 0.25 SWEP.Primary.Force = 1 SWEP.Secondary.ClipSize = 0 SWEP.Secondary.DefaultClip = 0 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.CSMuzzleFlashes = true SWEP.ShouldDropOnDie = true function SWEP:PrimaryAttack() if ( not self:CanPrimaryAttack() ) then return end ply = self.Owner ply:LagCompensation ( true ) local Number = math.random( 1 , 4 ) if (Number > 0.99 and Number < 2) then LaunchPly( self.Owner ) end if (Number > 1.99 and Number < 3 ) then timer.Create( "OriginalJump" , 5 , 0 , function() self.Owner:SetJumpPower( 200 )  ) UpLaunchPly( self.Owner ) end if (Number > 2.99 and Number < 4) then timer.Create( "OriginalSpeed", 5 , 0 , function() self.Owner:SetRunSpeed( 320 ) ) SpeedPly(self.Owner) end ply:LagCompensation ( false ) end}
1: you're not ending your timers.
Ah okay there is one. Is there more?
Okay now my code looks like this: if (Number > 2.99 and Number < 4) then SpeedPly(self.Owner) timer.Create( "OriginalSpeed" , 5 , 0 , SpeedNormal( ply ) ) end I still have the same error...
A couple of problems with this code: Every 5 seconds, it's going to keep calling "SpeedNormal". The timer is called wrong. Fix: if (Number > 2.99 and Number < 4) then SpeedPly(self.Owner) timer.Simple(5, function() SpeedNormal( ply ) end ) end
Thank you very much or your help and time! Have a good day!
Sorry, you need to Log In to post a reply to this thread.