local module = {}
local ownerships = {}
local refresh_cooldowns = {}
local text_cooldowns, image_cooldowns, owner_cooldowns = {}, {}, {}
local connections = {}
local min_price_global = 1000
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local modules = ReplicatedStorage.Modules
local data = require(script.Parent.Datastore)
local http_catalog = require(script.Parent.HttpCatalog)
local chat = require(script.Parent.Chat)
local shorten = require(modules.Shorten).shorten
local remotes = ReplicatedStorage.Remotes
local buttons_added_remote = remotes.ButtonsAdded
local purchase_remote = remotes.Purchase
local change_text_remote = remotes.ChangeStandText
local change_image_remote = remotes.ChangeStandImage
local change_owner_remote = remotes.ChangeStandOwner
local create_prompt_remote = remotes.EditProximityPrompt
local refresh_remote = remotes.RefreshListings
local stands = workspace.Stands
local function find_player_in_ownerships(player)
local user_id = player.UserId
for i, stand in ipairs(ownerships) do
if stand[2] == user_id then
return stand, i
end
end
end
local function filter_text(text, user)
local result = TextService:FilterStringAsync(text, user.UserId)
return result:GetNonChatStringForBroadcastAsync()
end
local function purchase_finished(player, product_id, was_purchased)
if was_purchased then
local product_info = MarketplaceService:GetProductInfo(product_id)
local price = product_info.PriceInRobux
local product_owner_id = product_info.Creator.CreatorTargetId
local product_owner = Players:GetPlayerByUserId(product_owner_id)
if player then
data.add_donated(player, price)
end
if product_owner then
data.add_raised(product_owner, price)
end
data.new_transaction()
if price >= min_price_global then
chat.SendToAll(string.upper(player.Name.." HAS DONATED "..shorten(price).." ROBUX TO "..product_info.Creator.Name.." !!"), "GLOBAL", false)
else
chat.Send(player.DisplayName.." has donated "..shorten(price).." ROBUX to "..product_info.Creator.Name.." !", "DONATION", false)
end
end
end
local function is_product_in_stand(stand_id, product_id)
local products = ownerships[stand_id][3]
for i, item in ipairs(products) do
if item[1] == product_id then
return i
end
end
local owner = game.Players:GetPlayerByUserId(ownerships[stand_id][2])
for i, item in ipairs(data.get_products(owner)) do
if item[1] == product_id then
return i
end
end
end
local function change_stand_text(player, text)
local stand = find_player_in_ownerships(player)
if stand then
text = string.sub(text, 1, 150)
if text_cooldowns[player.UserId] then
if tick() - text_cooldowns[player.UserId] < 1 then
return
end
end
text = filter_text(text, player)
stand[1].Text.Gui.TextLabel.Text = text
data.set_text(player, text)
text_cooldowns[player.UserId] = tick()
end
end
local function change_stand_image(player, id)
local stand = find_player_in_ownerships(player)
if stand then
if image_cooldowns[player.UserId] then
if tick() - image_cooldowns[player.UserId] < 1 then
return
end
end
if not string.find(tostring(id), "rbxassetid://") then
id = "rbxassetid://"..id
end
stand[1].Text.Gui.ImageLabel.Image = id
data.set_image(player, id)
image_cooldowns[player.UserId] = tick()
end
end
local function change_stand_owner(player, id)
local stand = find_player_in_ownerships(player)
if stand then
if owner_cooldowns[player.UserId] then
if tick() - owner_cooldowns[player.UserId] < 1 then
return
end
end
stand[1].Owner.Value = id
data.set_owner(player, id)
owner_cooldowns[player.UserId] = tick()
end
end
local function purchase(player, stand_id, product_id)
if player and stand_id and product_id then
if ownerships[stand_id] then
if is_product_in_stand(stand_id, product_id) then
MarketplaceService:PromptPurchase(player, product_id)
end
end
end
end
function module.refresh_listings(player)
local stand, i = find_player_in_ownerships(player)
if stand then
if refresh_cooldowns[player.UserId] then
if tick() - refresh_cooldowns[player.UserId] < 10 then
return
end
end
local listings_frame = stand[1].Listings.Gui.ScrollingFrame
local onsale_items = http_catalog.get_item_list(data.get_owner(player))
buttons_added_remote:FireAllClients(i, onsale_items)
refresh_cooldowns[player.UserId] = tick()
return onsale_items
end
end
local function claim_prompt_triggered(player, i)
if ownerships[i][2] == false then
if not find_player_in_ownerships(player) then
ownerships[i][2] = player.UserId
local stand = ownerships[i][1]
stand.Owner.Value = data.get_owner(player)
create_prompt_remote:FireClient(player, i, data.get_products(player))
stand.Claim.Claim.Enabled = false
stand.Text.Gui.ImageLabel.Image = data.get_image(player)
stand.Username.Gui.UsernameLabel.Text = player.DisplayName
stand.Text.Gui.TextLabel.Text = data.get_text(player)
stand.Raised.Gui.RaisedLabel.Text = "Raised R$".. shorten(data.get_raised(player))
connections[player.UserId] = {}
table.insert(connections[player.UserId], player.leaderstats.Raised.Changed:Connect(function()
stand.Raised.Gui.RaisedLabel.Text = shorten(data.get_raised(player))
end))
local products = module.refresh_listings(player)
ownerships[i][3] = products
end
end
end
function module.player_removing(player)
local stand, i = find_player_in_ownerships(player)
if stand then
refresh_cooldowns[player.UserId] = nil
buttons_added_remote:FireAllClients(i, {})
for _, connection in ipairs(connections[player.UserId]) do
connection:Disconnect()
end
connections[player.UserId] = nil
stand[1].Text.Gui.ImageLabel.Image = ""
stand[1].Owner.Value = 0
stand[1].Claim.Claim.Enabled = true
stand[1].Username.Gui.UsernameLabel.Text = "Unclaimed"
stand[1].Text.Gui.TextLabel.Text = ""
stand[1].Raised.Gui.RaisedLabel.Text = ""
stand[2] = false
stand[3] = {}
end
end
function module.player_added(player)
for i=1, #stands:GetChildren() do
local ownership = ownerships[i]
if ownership then
if ownership[2] then
buttons_added_remote:FireClient(player, i, ownership[3])
end
end
end
end
function module.initiate()
chat.ChatColor("DONATION", Color3.fromRGB(255, 245, 130))
chat.AddTag("DONATION", "💵")
chat.ChatColor("GLOBAL", Color3.fromRGB(255, 101, 101))
chat.AddTag("GLOBAL", "🌟")
for i, stand in ipairs(stands:GetChildren()) do
stand.Name = i
ownerships[i] = {stand, false, {}}
local owner = Instance.new("IntValue")
owner.Name = "Owner"
owner.Parent = stand
local ClaimProximityPrompt = script.Claim:Clone()
ClaimProximityPrompt.Parent = stand.Claim
ClaimProximityPrompt.Triggered:Connect(function(player)
claim_prompt_triggered(player, i)
end)
end
change_text_remote.OnServerEvent:Connect(change_stand_text)
change_image_remote.OnServerEvent:Connect(change_stand_image)
change_owner_remote.OnServerEvent:Connect(change_stand_owner)
MarketplaceService.PromptPurchaseFinished:Connect(purchase_finished)
purchase_remote.OnServerEvent:Connect(purchase)
refresh_remote.OnServerEvent:Connect(module.refresh_listings)
end
return module
Line 156