I'm adding this to my RPG, but when I tested it it aint no working. And I have no idea how to "make it work"
admins = {"Player", "dragonmaster4111"} game.Players.PlayerAdded:connect(function(plr) for i,v in pairs(admins) do if v == plr.Name then plr.Chatted:connect(function(msg) if msg:sub(1,5) == ";gold" then plr.leaderstats.Gold.Value = msg:sub(7) end end) end end end)
ALRIGHT AFTER I'VE TESTED FOR THE FIFTH TIME, IT WORKED!
Your script works perfectly fine in both Studio Server Test, and Studio Play mode. It could be entirely possible you are running the script in Studio Server Test which identifies players by Player then a number Player1
, Player2
, Player3
etc.
You might want to add Xetrax suggestion and make sure the value is a number before changing it. I personally use this technique;
if tonumber(msg:sub(7)) ~= nil then --If the string can not be converted to a number, then the function returns nil. --code here end
1: If the message isn't 7 characters long, this can throw an error. 2: Instead of the String.sub() method, I would use String.match(msg, "%d*"), which matches and returns any numbers found in the String, 0 or more. (Follow this link to learn more about this kinda stuff: http://wiki.roblox.com/index.php?title=String_patterns#Simple_matching ) 3: Your problem is simple to fix, don't use msg:sub(1, 5), use msg.sub(1, 5), same goes for msg:sub(7)
Hope this helps, if not, someone else is bound to give you the right answer; Regards, Xetrax