hello, I want to make a /setCoins and /addCoins command but the thing is idk what i should do anyone got an idea? My currency is Coins
✓ ANSWER ACCEPTED
How do i add a /setCoins and /addCoins command?
2 answers
✓ Accepted answer
You can use the Chatted event to detect when a player chats something, then you can use string.find() and string.split() to determine if it is a command, and what value they want to set/add. This would be a server script
Here are the links to the wikis:
https://developer.roblox.com/en-us/api-reference/event/Player/Chatted
https://developer.roblox.com/en-us/api-reference/lua-docs/string
Here is a sample script
-- lets assume that someone has said "/setCoins 50"
-- and assuming that setCoins means to set the coins, while addCoins is adding to the value
coins = player.leaderstats.Coins -- where are the coins located?
msg = "/setCoins 50" -- you would put a variable for the message inside the parentheses normally
-- v right here
player.Chatted:Connect(function()
if string.find(msg,"/setCoins") then
local value = string.split(msg," ")[2] -- gets the second string that is separated by a space in the msg
coins.Value = value -- aka setting
elseif string.find(msg,"/addCoins") then
local value = string.split(msg," ")[2]
coins.Value = coins.Value + value -- aka adding
end
end)
Hope this helps
it didn't work i tried it
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Well that is not a full script, but did anything come up in the output?
Nothing game in the output
i mean nothing was in the output