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

How can I make a donate chat command?

I want someone in the chat to type "/donate" and then a prompt of the donation purchase shows up. I tried but it horribly failed. can someone fix this for me? I don't have much scripting experience, thanks.

ProductID		= 999105219
ProductPrice	= 100
CurrencyType	= "R$"																				-- ROBUX > "R$"     |
MS				= game:GetService("MarketplaceService")
local function onPlayerChatted(player, message)
	if message == '/donate' and player.Character and player.Character:FindFirstChild("Head") then
		MS:PromptProductPurchase(Player,ProductID)
	end
end
local function onPlayerAdded(player)
	pl.Chatted:Connect(function (message) onPlayerChatted(player, message) end)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)

1 answer

Yes, I can fix this for you.

local MS = game:GetService("MarketplaceService")
local ProductID = 999105219
local ProductPrice = 100
local commandPrefix = '/' -- change this to your liking

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(MSG) -- Player chatted
		local NewMsg = string.upper(MSG) -- Converted message to all caps
		
		if NewMsg:sub(1,7) == commandPrefix .. "DONATE" then
			MS:PromptPurchase(player, ProductID)
		end
	end
end)

So basically, when the player chats, the callback supplies the function with the message that the player sent. What I did was convert this to all caps so that even if someone types in "/DoNaTe", it will still pass the if statement. The if statement is kind of complicated, so I'd recommend learning about string manipulation. If the statement is true then it prompts the player to buy your donate product.

I hope this helps :)

1 comment

0

i tried this but whenever i tested it, it the purchase prompt didn't show up

This discussion is preserved as it was. New answers, comments, and votes are closed.