Hello, I want to script a trading system similar to the one in Toilet Tower Defense for my Tower Defense game. I’m not asking for the script, I just need help with it because I already have a lot of scripting knowledge.
If you’re not asking for the full script then where do you need help in it?
I simply need help, what do i need to start with and how do i do it?
Then what do you need im confused-
Never mind the message above explains that.
I need some help for exemple you can tell me like how trading system with tables works and all of that
Sorry i gtg im sure other people will help you though!
Idk how to really but I’ve got an idea:
- Create a local trading handler
- Create a local script for SS to send data to
- Create a server trading handler
- Create events (so that the LS can talk to the SS and SS can talk to the LS) (LS=localscript SS=server script)
- Create UI
- In the UI create the chosen item to trade and a list of the players the player has below that. Create the second side for the player B that player A will be trading with
- Now for the local trading handler:
NOTE: YOU WILL NEED TO HAVE A PLACE WHERE YOU STORE THE PLAYER’S ITEMS (I suggest a folder in the player that will store each item)
- Create a function (probably a for i, v loop) that will create a imagebutton with the item image and with a numbervalue (Unique key) and stringvalue (In depth key) in it
- The stringvalue should have the item of the name as a value
- Now depending on if you want the other player to see the other player’s items then you will have to send an event with all the values and create imagelabels for the other player (basically you will need to send an event to replicate the first player’s UI for the second player)
- For the main item to trade create another function and in it place a for i, v loop and inside create a mousebutton1click (smth like that) and immediately connect it.
example:
for i, v in pairs(availablePlayerItems:GetChildren) do
v.MouseButton1Click:Connect(function()
end)
end
- Inside the mousebutton1click make the values inside the v parent to the imagebutton of the trading item and destroy the imagebutton you just clicked. Then make the imagebutton of the trading item update it’s image of the item its holding (the stringvalue value).
- Now for the removing just basically do the same thing but in reverse but don’t destroy the trading item imagebutton but just remove it’s image.
- Now for the server side script
- You will want to receive all of the events and values within those events that the local trading handler sends and save them as variable
Sorry thats all I can give you because I haven;t really worked on any trading system but here are the main foundations to work with. I hope I helped!
Thank you very much i will try this out when i will get on my pc!
Oh and obv hook it up to some sort of database to save the trade immediately after both players agreed on a trade, that even if a player disconnects before he gives the pet it, the other player cannot lose his pet, what do I mean by this? Basically its a little bit of real DB theory in a way that:
To ensure that even if a player loses connection but still hits conclude it doesnt end in a way:
- player A leaves and gets the pet but doesn’t give his pet
- player B gives his pet but doesn’t get player’s A pet
To make sure no such fraud occurs you can basically first update both player’s databases:
- Remove player’s A pet from player A and give him player’s B pet
- Remove player’s B pet from player B and give him player’s A pet
And after that the rest of the UI script can continue. Thanks to this none of the of the players can cheat their way out of the trade. Alr I hope it helps!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.