Why does this function not work?

This function works on single player but won’t work on multiplayer. It’s in my init.lua file and what it is supposed to do is drop 1-25 dollars randomly. but when you die nothing drops.


function GM:DoPlayerDeath( p, attacker, dmginfo )

  local amount = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"}
	p:RedNotify( "You got knocked the fuck out and lost "..CUR..Configuration["knockouttax"].."." )
	p:TakeMoney( Configuration["knockouttax"] )

	p:CreateRagdoll()

	p:ConCommand("gm_rp_dropcash " .. table.Random(amount))
	
end

Why isn’t the cash you drop the same as the knockouttax? Also let me introduce you to Math.random. Oh and you might want to check the player does have the money before dropping it. :slight_smile:


function GM:DoPlayerDeath( p, attacker, dmginfo )

	p:RedNotify( "You got knocked the fuck out and lost "..CUR..Configuration["knockouttax"].."." )
	p:TakeMoney( Configuration["knockouttax"] )

	p:CreateRagdoll()

	p:ConCommand("gm_rp_dropcash " .. math.random(1,20))
	
end

Apart from that I can’t really see a problem with it. Are you sure there’s no error from one of those functions blocking the script? Use Create Multiplayer to catch all errors in your console.

For some reason it works on create multiplayer but on my server it doesn’t is there a reason for that…

Did you hook the function?

No how would I hook it?

Taking a wild guess, if he declared the function in the gamemodes files, it should be hooked. Otherwise if it’s outside of the files it will need a hook.Add()