How to make a trade system?

Heyo I’ve never made a trade system before but I’m currently trying to attempt one and I just wanna know if the way I’m doing it is fine or dumb and like how can I make it better.

So I have 3 remotes at the moment TradeAccepted, TradeDeclined and TradeRequest and here’s my coding for it

--Sending Trade (Client)
module.TradeRequest = function(Parent,Button)
	--Parent.PlayerName.Text will be the name of the player who we're sending a trade request to
	TradeRequest:FireServer(Parent.PlayerName.Text)
end

--Receiving Trade Request (Server)
TradeRequest.OnServerEvent:Connect(function(PlayerRequested,PlayerToTrade)
	if --[[(Player.Name ~= PlayerToTrade) and]] (Players:FindFirstChild(PlayerToTrade)) then
		local PlayerToTrade = Players:FindFirstChild(PlayerToTrade)
		
		if table.find(GameSettings.NoTrade,PlayerToTrade.Name) then
			warn(PlayerToTrade.Name.." is not accepting trades")	
		elseif table.find(GameSettings.TradeByFriendsOnly,PlayerToTrade.Name) then
			if PlayerToTrade:IsFriendsWith(PlayerRequested.UserId) then
				TradeRequest:FireClient(PlayerToTrade,PlayerRequested.Name)
			else
				warn("Can't trade because not friends :(")
			end		
		else
			TradeRequest:FireClient(PlayerToTrade,PlayerRequested.Name)	
		end	
	end
end)

--Trade Notification (Client) 
TradeRequest.OnClientEvent:Connect(function(PlayerWhoSentTrade)
	--warn("You have a trade request from "..PlayerWhoSentTrade)
	TradeNotification:TweenPosition(UDim2.new(0.814,-10,0.82,-10),"Out","Sine",0.4,true)
	TradeNotification.TextLabel.Text = "You have a trade request from "..PlayerWhoSentTrade
	TradeNotification.Value.Value = PlayerWhoSentTrade --store the person who sent trade in value which will be used later
end)

--If The Player Hits Accept On The Trade Notification (Client)
module.Accept = function(Parent,Button)
	local PlayerWhoSentTrade = Parent.Value.Value --probs lazy/dumb way to do this, but IDK WHAT ELSE TO DO IT'S 11AM AND IM WORKING OFF OF MONSTER
	TradeList.Visible = false
	TradeAccepted:FireServer(PlayerWhoSentTrade)
	TradeNotification:TweenPosition(UDim2.new(1.1,-10,0.82,-10),"Out","Sine",0.4,true)
end

--Trade Accepted (Server) 
--Player is the player who received trade
TradeAccepted.OnServerEvent:Connect(function(Player,PlayerWhoSentTrade)
	TradeAccepted:FireClient(Players:FindFirstChild(PlayerWhoSentTrade)) 
	TradeAccepted:FireClient(Player)	
end)

2 Likes

Seems fine to me!

Didn’t know table.find was a thing, thanks!

1 Like

you should be able to type “table.” and roblox should show you options you could choose from

there are many great things in there :smiley: