Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do i add a /setCoins and /addCoins command?

Asked by 3 years ago

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

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

Ad
Log in to vote
0
Answered by 3 years ago

it didn't work i tried it

0
Well that is not a full script, but did anything come up in the output? Omq_ItzJasmin 666 — 3y
0
Nothing game in the output legendisa456 7 — 3y
0
i mean nothing was in the output legendisa456 7 — 3y

Answer this question