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
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