SetBaseKarma error


 [ERROR] lua/autorun/karmareset.lua:13: attempt to call method 'SetBaseKarma' (a nil value) 
1. fn - lua/autorun/karmareset.lua:13 
2. Call - addons/ulib/lua/ulib/shared/hook.lua:365 
3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:131 
4. func - gamemodes/terrortown/gamemode/cl_init.lua:204 
5. unknown - lua/includes/modules/net.lua:63 

^get this error with this code v


 function karmreset()
	for k,ply in pairs (player.GetAll()) do
		if ply:IsUserGroup("BlackCrystal") then
			ply:SetBaseKarma(1500)
			ply:SetLiveKarma(1500)
		end
	end
end

hook.Add("TTTBeginRound", "karmreset", karmreset) 

it works but get the fucking error D:

and dont find anything on google or facepunch :confused:

You’re using player.GetAll( );, you may have some players that are currently connecting or whatever…

Add this line before your if ply:IsUserGroup…


if ( !IsValid( ply ) ) then continue; end

same error

Use this one then:


if ( !IsValid( ply ) || !ply.SetBaseKarma || !ply.SetLiveKarma ) then continue; end

Basically, if the player object is invalid or either of the meta-table functions ( SetBaseKarma, SetLiveKarma ) aren’t defined then skip.

Your addon may not be adding the meta-table functions properly.