Hello! I would like to know how to make a chat command that adds cash. For Example: !AddMoney Playername amount Any help?
How do I make a chat command that adds cash?
2 answers
Hello. You could do something like this: I have made two commands, !setmoney player value and !addmoney player value !addmoney increments the value given by the current amount of money you have
You could add this to an admin script too:
local function NameShortening(nameString)
local matches= {}
for _, player in ipairs (game.Players:GetPlayers()) do
if string.lower(player.Name):match(string.lower(nameString)) then
table.insert(matches, player)
end
end
if #matches== 1 then
return matches[1]
else
return nil
end
end
local function onChatted(msg, speaker)
if string.find(msg:lower(), "!setmoney") then
local a,b,name,amount = string.find(msg, "!setmoney (%S+) (%S+)")
local name2 = NameShortening(name)
if name2 ~= nil then
if typeof(tonumber(amount)) == "number" then
game.Players:FindFirstChild(tostring(name2)).leaderstats:FindFirstChild("Cash").Value = tonumber(amount)
else
print("Invalid input entered!")
end
else
print("Invalid player entered!")
end
end
if string.find(msg:lower(), "!addmoney") then
local a,b,name,amount = string.find(msg, "!addmoney (%S+) (%S+)")
local name2 = NameShortening(name)
if name2 ~= nil then
if typeof(tonumber(amount)) == "number" then
game.Players:FindFirstChild(tostring(name2)).leaderstats:FindFirstChild("Cash").Value = game.Players:FindFirstChild(tostring(name2)).leaderstats:FindFirstChild("Cash").Value + tonumber(amount)
else
print("Invalid input entered!")
end
else
print("Invalid player entered!")
end
end
end
game.Players.PlayerAdded:connect(function(player)
player.Chatted:Connect(function(msg)
onChatted(msg, player)
end)
end)
For an admin script, you could change the bottom bit too:
game.Players.PlayerAdded:connect(function(player)
player.Chatted:Connect(function(msg)
if tostring(player) == "AdminPlayerName" then
onChatted(msg, player)
end
end)
end)
1 comment
Thank you!
Firstly you can do in studio or you can play it, it does not matter. You would need to open console, if you don't know the command here is the command: /console.
Once you have open it go and click "Sever" then type the code below but change "NAMEHERE" to whatever username you like to give cash to.
game.Players.NAMEHERE.leaderstats.Money.Value = AmountOfCashHere
NOTE: If you don't use "Money" then change it to whatever you are using.
If there any problem then let me know.
1 comment
no i mean a chat command where you can type in chat !addmoney not in console
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
You should attempt the problem yourself. Alternatively, if you study how admin scripts work (in free models), you will learn how to do what you ask.
https://devforum.roblox.com/t/how-to-make-basic-admin-commands/59691/5
it don't work