*Help* Simple issue in need of a true Lua coder expertise!

Hi guys I have a script which is simple and has a simple issue with it.
If your going to help please no TTT Crap, I need a true Lua coder to resolve this.

I have a client side HUD paint function. This is used to display end game results to the clients.

This is what I am using to display who had the most kills and what the number of kills was. I will show it within the whole function so you can get to grips with how it works.





function GM:DrawEndHUD()
local ply = LocalPlayer()
	local imagessplat = Material("Endgame.png") --Simulation over screen
local mostkills = -1 local winrar for k,v in pairs(player.GetAll()) do if v:Frags() > mostkills then mostkills = v:Frags() winrar = v --End round for most kills calculation.

	end 
	end 

	surface.SetMaterial(imagessplat) --Draw the end game screen 
surface.SetDrawColor(225, 225, 225,220 )
	  surface.DrawTexturedRect(0, 0, ScrW()/1, ScrH()/1 )

	draw.DrawText( "The vitor was..", "MyFont2", ScrW() * 0.42, ScrH() * 0.5, Color( 144,200,149,255 ), TEXT_ALIGN_CENTER ) --End round scoring for most kills.
	draw.DrawText( "kills!", "MyFont2", ScrW() * 0.58, ScrH() * 0.5, Color( 144,200,149,255 ), TEXT_ALIGN_CENTER ) 
	draw.SimpleText( winrar:GetName(),"MyFont2", ScrW() * 0.51, ScrH() * 0.5, Color( 144,200,149,255), TEXT_ALIGN_CENTER )
	draw.SimpleText( mostkills, "MyFont2", ScrW() * 0.55, ScrH() * 0.5, Color( 144,200,149,255 ), TEXT_ALIGN_CENTER )
end



Now this is the part causing the issue.




local mostkills = -1 local winrar for k,v in pairs(player.GetAll()) do if v:Frags() > mostkills then mostkills = v:Frags() winrar = v --End round for most kills calculation.

	end 
	end 



This is the error I receive.



attempt to index local 'winrar' <a nil value>


If I get a negative value aka -1 kills or -2 etc… I get this error. I really don’t know how to resolve it.

If you have an answer to how this would be resolved I would be greatly appreciated.

sorry for being formal but I need this resolved asap.

Thanks

Duby

I am pretty sure this script isn’t yours.

Anyway, the issue is, “v:Frags() > mostkills” is false for all the players on server.
Either set “local mostkills = -1” to like “-99999” or set “winrar” variable to a random player initially, or if at the end of the loop “winrar” is nil, set it to something, or add IsValid checks in your drawing code, or find another solution that suits you.

That seems like a way to fix it. Hmm ok thanks I give it a go!

FYI: It is my scripts I spent a long time infact 8 months working on my GM sLayer, look on the gamemode section. So its quite hurtful for someone to say that. :stuck_out_tongue: