How to make like trading system

I am a beginner and would like to create a trading function that is common in simulator games. However, I don’t quite understand the structure of sharing or exchanging data with other players. Could you tell me how to share data with a simple player?

example:
When player1 presses the textbutton, a message is sent to player2

When player1 presses the textbutton, the specified amount of coins (leaderstats.coin) is awarded to player2.

Here’s some simple code think of it this way there are 2 players Player 1 and Player 2, you put a TextButton and a script:

script.Parent.MouseButton1Up:Connect(function(plr) --basically it activates when the button is pressed

Local Playerwanted = game.workspace.Player2--gets the other player

Playerwanted.leaderstats.coins.Value += 50

end


end)
1 Like

Thanks for the answer! This solved one problem

1 Like

btw i want to know other 1
When player1 presses the textbutton, a message is sent to player2

correct me if im wrong but isn’t leaderstats stored in game.Players.playerwanted instead of workplace?

I think your meant to do

plrs = game:GetService(“Players”)
player1 = plrs.LocalPlayer
player2 = plrs:FindFirstChild(“player2”)
givingcoins = 100

player1.leaderstats.coins -= givingcoins
player2.leaderstats.coins += givingcoins

this is just a rough idea what the code would look like
please correct me if im wrong

For the first one, you would need to use remote events to communicate from the local players UI to the server, which would give information regarding items/coins ect. The server would then communication with the player2 from there. If you don’t know how to use remote events there is plenty of youtube tutorials

thanks for reply!
I will refer to

That would be one way to do it, however, if you’re looking for security, this is the most vulnerable. However, it’s up to the developer to choose which way they want to handle currency!

1 Like