Error - I can't figure it out

ERROR: GAMEMODE:‘Think’ Failed: GModRPbase/gamemode/init.lua:216: attempt to call method ‘StaminaCheck’ (a nil value)

^ thats in blue writing - it was ‘staminaCheck’ at first and I capitalized it, but that doesnt fix it - and sorry im not sure how to ‘write in code sections’

(im messing with GMODRP)

Well im just a starter lua guy but when it says

im pretty sure your error is on line 216 so whatever the issue is, its on that line, copy that line and show us. Also when it says its nil, then it means nothing so make sure it has a value

I’m almost a total noob aswell

start210 - end226


function GM:Think()

	for _, ply in pairs( player.GetAll() ) do	
	
		if ply:IsValid() then
	
			ply:StaminaCheck()
			
			ply:CheckHunger()		
		
			if ply:GetNWBool( "ishigh" ) then
			
				if ply:GetVelocity():Length() > 0 then

					ply:SetVelocity( Vector( math.random( -50, 50 ), math.random( -50, 50 ), 0 ) )
					
				end	

I just copy pasted the whole of line 216 from NP++ - im not sure how its wrong is all… :frowning:

You need to end the if statements aswell as the function. Similar mistake I made awhile ago - I’m very new to lua aswell.

So where would the 2nd end go - direct under the ‘function’ typed above or what/where?

Try this:
[lua]function GM:Think()

for _, ply in pairs( player.GetAll() ) do    

    if ply:IsValid() then

        ply:StaminaCheck()
        
        ply:CheckHunger()        
    
        if ply:GetNWBool( "ishigh" ) then
        
            if ply:GetVelocity():Length() > 0 then

                ply:SetVelocity( Vector( math.random( -50, 50 ), math.random( -50, 50 ), 0 ) )
                
            end
        end
    end
end

end[/lua]

Oh i think i get it - there a trail line goin downwards to an ‘end’ - but there isnt one going from the StaminaCheck line… so if i typed end further down and lined them up a line should appear?

[lua]local meta = FindMetaTable(“Player”)

function meta:StaminaCheck()
– do stuff
end[/lua]

Did people in this forum forget how to read errors or something? (The people who helped)

OMFG I feel either really stupid or the best ever noob - how is this?


function GM:Think()

	for _, ply in pairs( player.GetAll() ) do	
	
		if ply:IsValid() then
	
			ply:StaminaCheck()
			
			   ply:CheckHunger()		
		
			        if ply:GetNWBool( "ishigh" ) then
			
				       if ply:GetVelocity():Length() > 0 then

					      ply:SetVelocity( Vector( math.random( -50, 50 ), math.random( -50, 50 ), 0 ) )
					
				       end	
				
			       end	
            
			   end			
			
			 if ply.NextO2Think == nil then
			
				ply.NextO2Think = 0
				
			end	

The errors have gone - but the HL2 stock weapons appear in inventory - unlike before when the ‘speshull’ GMODRP items were there…

You just ruined your tabbing. Only tab in when there is something to indent - an if statement, loop or function.

So not each of those line has to trail down to an end?

No.

Ive been playing around with it and still its not fixed - GM_GiveSWEP is not working now either


function GM:Think()
 
        for _, ply in pairs( player.GetAll() ) do       
       
                if ply:IsValid() then
       
                        ply:StaminaCheck()
                       
                           ply:CheckHunger()           
               
                                if ply:GetNWBool( "ishigh" ) then
                       
                                       if ply:GetVelocity():Length() > 0 then
 
                                              ply:SetVelocity( Vector( math.random( -50, 50 ), math.random( -50, 50 ), 0 ) )
                                       
                                       end     
                               
                               end     
           
                           end                 
                       
                         if ply.NextO2Think == nil then
                       
                                ply.NextO2Think = 0
                               
                        end     
               
                        if CurTime() > ply.NextO2Think then
                       
                                if !ply:Alive() then return end        
                               
                                if !ply.O2 then
                               
                                        if ply:WaterLevel() > 0 then
                                       
                                                ply:TakeDamage( 5, ply, ply )   
                                               
                                        end
                                       
                                end     
                               
                                ply.NextO2Think = CurTime() + 1
                               
                        end
                       
                end     
               
        end

Ive got a pastebin going if anyone can show me how to solve it better than my failed attempts :frowning:

Still having the same problems, 24h bump