So I have an idea for a Roblox game that works like the stock market.
Is it possible for me to script a situation where one person buys a stock with real Robux, and that Robux goes to someone else who sells the stock? I don’t know if it’s possible because of Roblox’s taxes.
If this is possible, could someone explain this to me or give me a workaround that works almost as well? Thank you for any help!
local function BuyStock(player, stockName, amount)
-- Deduct the appropriate amount of Robux from the player's account
local price = GetStockPrice(stockName) * amount
local success, err = pcall(function()
MarketplaceService:PromptProductPurchase(player, StockProductIds[stockName], nil, nil, true)
end)
if not success then
error("Purchase failed: " .. err)
end
-- Store the transaction in a separate datastore
local TransactionsStore = DataStoreService:GetDataStore("TransactionsStore")
local transaction = {
type = "buy",
player = player.UserId,
stock = stockName,
amount = amount,
price = price,
timestamp = os.time()
}
TransactionsStore:SetAsync(tostring(os.time()), transaction)
-- Give the player the appropriate amount of stocks
local StocksStore = DataStoreService:GetDataStore("StocksStore")
local stocks = StocksStore:GetAsync(player.UserId) or {}
stocks[stockName] = (stocks[stockName] or 0) + amount
StocksStore:SetAsync(player.UserId, stocks)
end
the MarketplaceService takes a 30% commission on all sales