What am i doing wrong D;


sleep.lua:14: '<name>' expected near 'if'

[lua]

function sleep(ply)

    local sleeping = pl:GetNWInt( "sleeping" )

    
    if sleeping &gt; 0 then -- line 14
        ply:Spawn()
        Msg("IM AWAKE!"
    else
        
            pl:SetNWInt( "sleeping", 1 )
            ply:Freeze( true )
            ply.sp = ents.Create( "prop_ragdoll" )
            ply.sp:SetPos( p:GetPos() )
            ply.sp:SetAngles( Angle( 0, p:GetAngles().Yaw, 0 ) )
            ply.sp:SetModel(p:GetModel())
            ply.sp:Spawn()
            ply.sp:Activate()
            ply.sp:SetVelocity( p:GetVelocity() )
            ply.oldHealth = p:Health()
            ply.oldEnergy = p:GetNWInt( "energy" )        
            ply:StripWeapons()
            ply:Spectate( OBS_MODE_CHASE )
            ply:SpectateEntity( p.sp )
            Msg("SLEEEEEEP..."
            -- Profit???
    end    

end

[/lua]
Were have i gone wrong?

Well, you seem to be messing an end parentheses on your Msg statements, but I don’t think that would affect your problem.

No :stuck_out_tongue: i just put them in quickly for FP.

I spotted other errors, you are using p and pl when you are defining ply, and you are missing a bracket for the Msg()

Oh, that too. Do ply:GetNWInt, not pl.

Yeah, i figured that out before Wablur posted, It was just an example, and its working.
One more problem though.
When i use the function, it only respawns me.
Any thoughts?

Do you get the message: “I’m awake!” in console?

Yes.