SetCredits

When i to do


ply:SetCredits( 10 )

It returns


lua:46: attempt to call method 'SetCredits' (a nil value)s

What are you trying to do?
What are credits?

My bad. Trying to set TTT credits while playing as a detective or a traitor

Show us where you get ply from, what is it in your code exactly



concommand.Add("GiveCredits", function(ply, credits)
	ply:SetCredits( credits )
end)


It’s supposed to be player, command, arguments for the function’s parameters.

Then you get the amount of credits in the function with arguments[1]

[lua]concommand.Add(“GiveCredits”, function(ply, command, arguments)
ply:SetCredits(arguments[1])
end)[/lua]

sony im confused. Can you please show me example code? U can use the one i showed here

I edited my post.

You’re basically giving an unlimited amount of credits to anyone that types that command, even if you do it right.

[lua]
concommand.Add( “GiveCredits”, function( ply, cmd, args )

if !ply:IsUserGroup( 'superadmin' ) then return end

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

	if string.lower( string.find( x:Nick(), args[1] ) ) then
	
		x:AddCredits( tonumber( args[2] ) )
		
	else
	
		ply:SendLua( string.format( 'print("No player found by the name %s.")', args[1] ) )
		
	end
	
end

end)
[/lua]

lua/autorun/server/x.lua

Didn’t test this, but give it a go

Im sorry i still dont get it how would you call it? This is what i tried


RunConsoleCommand("XriX_Credits", ply, 50, 50)

and i got as an error


lua:96: bad argument #2 to 'find' (string expected, got nil)

[lua]RunConsoleCommand(“XriX_Credits”, ply:Nick(), 50)[/lua]