How Do I Handle This?

hello im a semi-new roblox developer and im trying to create a sell system to improve my coding. In this system players can put thier items up for sale and other players can purchase them (like a marketplace).

my problem is that when a player puts a item up for sale i dont know how to clone the template. since i want all the players to see what the player put up for sale i dont know if i should clone the template on the server side or client side. I have 2 remote events to handle selling and buying which have not been used in my code yet.


-- local rep = game:GetService("ReplicatedStorage")
local openDealerEvent = rep.OpenDealer
local sellEvent = rep.SellItem

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.Character:Wait()

local gui = script.Parent
local itemsForSaleFrame = gui.ItemsForSaleFrame
local closeitemsbutton = itemsForSaleFrame.CloseButton
local GoToSellPageButton = itemsForSaleFrame.SellButton
local itemsFrame = itemsForSaleFrame.ItemsFrame
local itemsScrollingFrame = itemsFrame.ItemsScrollingFrame

local template = script.Template
local priceText = template.PriceFrame.PriceTextLabel
local toolNameText = template.ToolNameFrame.ToolNameTextLabel
local purchaseButton = template.BuyButton
local toolImage = template.ToolImage

local sellYourItemsFrame = gui.SellYourItemsFrame

itemsForSaleFrame.Visible = false
sellYourItemsFrame.Visible = false

local backbutton = sellYourItemsFrame.BackButton
local sellFrame = sellYourItemsFrame.SellFrame

local DetialsFrame = sellFrame.DetailsFrame
local SellToolName = DetialsFrame.SellToolNameFrane.ToolNameToSellText
local SellToolImage = DetialsFrame.ToolImage

local SellPriceText = sellFrame.PriceTextFrame.PriceText
local SubtractButton = sellFrame.SubtractPriceButton
local AddPriceButton = sellFrame.AddPriceButton

local sellButton = sellFrame.SellButton

local SellPrice = SellPriceText.SellPrice

local function CloneTemp(player)
	
end


SellPriceText.Text = "$" .. tostring(SellPrice.Value)

SellPrice:GetPropertyChangedSignal("Value"):Connect(function()
	SellPriceText.Text = "$" .. tostring(SellPrice.Value)
end)

AddPriceButton.MouseButton1Click:Connect(function()
	SellPrice.Value += 25
end)

SubtractButton.MouseButton1Click:Connect(function()
	if SellPrice.Value >= 25 then
		SellPrice.Value -= 25
	else
		SellPrice.Value = 0  -- Set SellPrice to 0 if it's below 25
	end
end)

openDealerEvent.OnClientEvent:Connect(function()
	if itemsForSaleFrame.Visible == false then
		itemsForSaleFrame.Visible = true
		
	elseif itemsForSaleFrame.Visible == true then
		itemsForSaleFrame.Visible = false
	end
end)

closeitemsbutton.MouseButton1Click:Connect(function()
	itemsForSaleFrame.Visible = false
	sellYourItemsFrame.Visible = false
end)

GoToSellPageButton.MouseButton1Click:Connect(function()
	itemsForSaleFrame.Visible = false
	sellYourItemsFrame.Visible = true
end)

backbutton.MouseButton1Click:Connect(function()
	itemsForSaleFrame.Visible = true
	sellYourItemsFrame.Visible = false
end)

1 Like

In guis,u should clone the template on the client side but…

If it is tools or other stuff dp that cloning on the server side

Also,it is the same as how u clone the tools

1 Like

and all players would be ablle to see the template that was cloned?

No.it is safe because it is the client side so only one player will see it

Whereas for servers,evetyone sees it

ohh ok so i need to clone it on the server?

Clone it on the client will be a wise choice

(FOR GUIS or for parts ONLY)

You are just trying to send data about the item no? Have the server facilitate client → all clients communication where the player tells the server that they have taken or put up an item on the market (also verify the legitimacy of this transaction), then have the server send that information to all the other clients. Each client then adds the appropriate visuals.

TLDR: Clone on the client, it’s easier and safer.

1 Like

You’d need to have the plr locally signal that they want to put it up for sale in the marketplace. Then, send that info to the server where you can store it in a data store and fire all clients. When you fire al clients, clone the template with info sent to the original client to the server and then to all clients. You’d have the info of what client had originally submitted it into the market, so you’d ignore that plr when duplicating it (so they can’t buy their own item.) When a plr buys it, use the server to subtract money, give the tool, change a data… if that makes sense?? Seems pretty straightforward,

1 Like

It’s always best to handle everything security wise on the server (for the most part), and handle the visuals on the client.

Therefore you should have a template on the server, and tell the clients to replicate that template on their local machine, using the data the server provides. Hope I helped.

1 Like