Whats Wrong With My Code?

Hello everyone, I tried to change some code from a chair thrower to a baby thrower. It doesn’t work. Any help appreciated.(Im a beginner)

This is an error my friend found when i asked him about it. https://gyazo.com/29eebea8501345491eda66a6903f9d48 [Not sure if its the only one. LOL]



[lua]WEP.PrintName = “Baby Thrower” – Name of SWEP
SWEP.Author = “” – Author’s Name
SWEP.Instructions = “Left Click To Throw A Baby!” – How to use SWEP

– Spawn Information –

SWEP.Spawnable = true – Is it Spawnable?
SWEP.AdminOnly = true – Is it Admin Only?

– Clip Information –

SWEP.Primary.ClipSize = -1 – Left Click Clip Size?
SWEP.Primary.DefaultClip = -1 – Left Click Default Clip Size
SWEP.Primary.Automatic = true – Automatic?
SWEP.Primary.Ammo = “none” – Left Click Ammo?

SWEP.Secondary.ClipSize = -1 – Right Click ClipSize?
SWEP.Secondary.DefaultClip = -1 – Right Click Default Clip Size
SWEP.Secondary.Automatic = false – Automatic?
SWEP.Secondary.Ammo = “none” – Right Click Ammo?

– More Information –

SWEP.Weight = 5 – How much does it weigh?
SWEP.AutoSwitchTo = false – Auto Switch To When Spawned?
SWEP.AutoSwitchFrom = false – Auto Switch From It?
SWEP.Slot = 1 – Slot Number?
SWEP.SlotPos = 2 – Slot Position?
SWEP.DrawAmmo = false – Draw Ammo?
SWEP.DrawCrosshair = true – Make Crosshairs?

– Models –

SWEP.ViewModel = “models/weapons/v_pistol.mdl” – What you see
SWEP.WorldModel = “models/weapons/w_pistol.mdl” – What other’s see

– Sound Prechache –

local ShootSound = Sound ( “phx/explode01.wav” ) – Prechache Sound, Used later on

– Baby Shoot On Left Click

function SWEP:PrimaryAttack()
– Weapon is automatic. Function Call below defines firerate
– Set to shoot every 0.5 Seconds
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )

-- Call "Throw Baby" on self with this model
self:ThrowBaby( "models/props_c17/doll01.mdl" )


function SWEP:SecondaryAttack()
– Weapon is not automatic so no call needed.
self:ThrowBaby( “models/props_c17/doll01.mdl” )

– Custom Function

function SWEP:ThrowBaby( “models/props_c17/doll01.mdl” )
– Play the shoot that is precached
self:EmitSound( ShootSound )

if ( CLIENT ) then return end

-- Create prop_physics entity
local ent = ents.Create( "prop_physics" )

-- Always make sure that created entities are actually created
if ( !IsValid( ent ) ) then return end

-- Set the entity's model
ent:SetModel( models/props_c17/doll01.mdl)

-- Set the position to player's eye position plus 16 units forward.
-- Sets the angles to the player's eye angles. Then spawn it.
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )

-- Get Prop Physics
local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent:Remove() return end

-- Apply Force
local velocity = self.Owner:GetAimVector()
velocity = velocity * 100
velocity = velocity + ( VectorRand() * 10 ) -- Random Element
phys:ApplyForceCenter( velocity )

-- This is just a random function in-case you are in sandbox mode!
cleanup.Add( self.Owner, "props", ent )

undo.Create( "Thrown_Baby" )
    undo.AddEntity( ent )
    undo.SetPlayer ( self.Owner )



Firstly, just so you know, you can use [lua] tags to make your code look nice in the forums. For example:
a]function Hello()
print(“Hello World!”)

Would look like this:
[lua]function Hello()
print(“Hello World!”)

Now, for your problem. The problem is that you replaced too much. Only where it says “models/props_c17/FurnitureChair001a.mdl” in the original code, you should replace it with the model you want. You replaced other stuff, like model_file (which is actually a parameter, not a string). That’s what’s causing problems.

I suggest you start over, take the original code and try again, and this time pay more attention to what you’re doing and what the purpose is.

function SWEP:ThrowBaby( models/props_c17/doll01.mdl )

You have to use a parameter name there, like ThrowBaby( model ). The model path should only be used once, when you CALL that function. Also, paths are strings, you should enclose them between quotation marks. I suggest you read a bit about basic programming, or at least the main LUA documentation before trying to modify example scripts.