Error: hook->PlayerSay returned a non-string!

the error i got is in the title and thats the code:



function GM:PlayerSay(Player, Text, Global)
	local ExplodedString = string.Explode(" ", string.lower(Text));
	if(ExplodedString[1] == "!give") then
		GiveCash(Player, Text);
		return "";
	end
end


how can i fix this?
thanks.

ok well.
You are returning a string so that shouldnt be an issue. I belive the answer to your problem is that your breaking the GiveCash function. I’m assuming that give cash takes player then number if so you will need this.

[lua]
function GM:PlayerSay(Player, Text, Global)
local ExplodedString = string.Explode(" ", string.lower(Text));
if ( ExplodedString[1] == “!give” ) then
GiveCash(Player, tostring(ExplodedString[2]) );
return “”;
end
end
[/lua]

If you notice in your code your doing this [lua]GiveCash(Player, “!give 1000”);[/lua]
Aka thats a string so you need to only give the number. But also the number is a string so it needs to be converted to a number. [lua]GiveCash(Player, tostring(ExplodedString[2]) );[/lua]

the command is !give [Who] [Amount]
example: !give D1ma 1000
and GiveCash also exploding the Text

and the error showing even if the first word is not “!give”

You’re overwriting the default hook and are not doing anything when if(ExplodedString[1] == “!give”) returns false. Make sure you return something when it returns false.

In other words, add else return Text to your code.

Not necessary and will only break things (Ignore what I said before this)

Oh, wait. Yeah. That only applies to hooks. return text, or call the baseclass.

the same with this code:
[lua]
function GM:PlayerSay(Player, Text, Global)
local ExplodedString = string.Explode(" ", string.lower(Text));
if(ExplodedString[1] == “!give”) then
GiveCash(Player, Text);
return “”;
else
return Text;
end
end
[/lua]

[lua]function GM:PlayerSay(pl, txt, team)
local ExplodedString = string.Explode(" ", string.lower(txt));
if(ExplodedString[1] == “!give”) then
GiveCash(pl, txt);
return “”;
end

return self.BaseClass:PlayerSay(pl , txt , team)

end[/lua]

Try that.