Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a chat command that adds cash?

2 answers

✓ Accepted answer

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

0

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

0

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.