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

How do I make a chat command that adds cash?

Asked by 5 years ago

Hello! I would like to know how to make a chat command that adds cash. For Example: !AddMoney Playername amount Any help?

0
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. chess123mate 5873 — 5y
0
it don't work Suhailpro777 0 — 3y

2 answers

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

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)
0
Thank you! ixUltraz 28 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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.

0
no i mean a chat command where you can type in chat !addmoney not in console ixUltraz 28 — 5y

Answer this question