TorNix~|nR Posted August 2, 2017 Share Posted August 2, 2017 guys the script works fine, but the line 16 and 17 have problem :attempt to concatenate local 'targetPlayer' (a userdata value) help please? addCommandHandler("sendmoney",function(player,cmd,targetPlayer,money) money = tonumber(money) and math.floor(tonumber(money)) or nil if not (targetPlayer) or not (money) then outputChatBox("use /" .. cmd .. " [Player] [Amount]",player,255,0,0,true) else local targetPlayer = getPlayerFromName (targetPlayer) local sourcename = getPlayerName (source) if targetPlayer then if (targetPlayer==player) then outputChatBox(" You cant give money to yourself.",player,255,0,0,true) elseif money <= 0 then outputChatBox(" Minimum ammount is 0.",player,255,0,0,true) elseif getPlayerMoney(player) >= money then takePlayerMoney(player,money) givePlayerMoney(targetPlayer,money) outputChatBox ( "You gave " .. targetPlayer .. " " .. money .. "$", source, 0, 255, 0, true) -- THIS LINE outputChatBox ( "" .. sourcename .. "gave you " .. money .. "$", targetPlayer, 0, 255, 0, true ) -- THIS LINE else outputChatBox(" You dont have enough money.",player,177,9,45,true) end end end end) Link to comment
Mr.Loki Posted August 2, 2017 Share Posted August 2, 2017 (edited) If you were trying to use the function parameter "targetPlayer" as the target player's name you can't because line 6 overrides it. You need to either change the name of the variable that holds the actual player at line 6 or change the function parameter's "targetPlayer" to "targetPlayerName" and use that at line 16. Also in line 16 source is not defined use "player" as it is what you defined as the player who uses the command in your function parameter. EDIT: I also suggest using getPlayerFromPartialName so u don't have to type the player's FULL name each time you use the command what if someone's name is jackthepro1164 all u gotta type is jac or 164 , thep etc.. Edited August 2, 2017 by Mr.Loki Link to comment
TorNix~|nR Posted August 2, 2017 Author Share Posted August 2, 2017 same 15: attempt to concatenate local 'targetPlayerName' (a boolean / userdata value) addCommandHandler("sendmoney",function(player,cmd,targetPlayer,money) money = tonumber(money) and math.floor(tonumber(money)) or nil if not (targetPlayer) or not (money) then outputChatBox("use /" .. cmd .. " [Player] [Amount]",player,255,0,0,true) else local targetPlayerName = getPlayerFromName (targetPlayer) if targetPlayer then if (targetPlayer==player) then outputChatBox(" You cant give money to yourself.",player,255,0,0,true) elseif money <= 0 then outputChatBox(" Minimum ammount is 0.",player,255,0,0,true) elseif getPlayerMoney(player) >= money then takePlayerMoney(player,money) givePlayerMoney(targetPlayerName,money) outputChatBox ( "You gave " .. targetPlayerName .. " " .. money .. "$", player, 0, 255, 0, true) -- THIS LINE outputChatBox ( "" .. player .. "gave you " .. money .. "$", targetPlayer, 0, 255, 0, true ) -- THIS LINE else outputChatBox(" You dont have enough money.",player,177,9,45,true) end end end end) 1 Link to comment
TorNix~|nR Posted August 2, 2017 Author Share Posted August 2, 2017 Thanks for everything, I gave up. 1 Link to comment
Mr.Loki Posted August 2, 2017 Share Posted August 2, 2017 addCommandHandler("sendmoney",function(player,cmd,targetPlayerName,money) money = tonumber(money) and math.floor(tonumber(money)) or nil if not (targetPlayerName) or not (money) then outputChatBox("use /" .. cmd .. " [Player] [Amount]",player,255,0,0,true) else local targetPlayer = getPlayerFromName (targetPlayerName) if targetPlayer then if (targetPlayer==player) then outputChatBox(" You cant give money to yourself.",player,255,0,0,true) elseif money <= 0 then outputChatBox(" Minimum ammount is 1.",player,255,0,0,true) elseif getPlayerMoney(player) >= money and money > 0 and targetPlayer~=player then takePlayerMoney(player,money) givePlayerMoney(targetPlayer,money) outputChatBox ( "You gave " .. targetPlayerName .. " " .. money .. "$", player, 0, 255, 0, true) -- THIS LINE outputChatBox ( "" .. player .. "gave you " .. money .. "$", targetPlayer, 0, 255, 0, true ) -- THIS LINE else outputChatBox(" You dont have enough money.",player,177,9,45,true) end end end end) You have to read through your code carefully. Link to comment
itHyperoX Posted August 2, 2017 Share Posted August 2, 2017 (edited) . Edited August 2, 2017 by TheMOG 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now