Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --VARIABLES
- local client = game.Players.LocalPlayer
- local rs = game.ReplicatedStorage:WaitForChild("TradeReplicatedStorage")
- local re = rs:WaitForChild("RemoteEvent")
- local config = require(rs:WaitForChild("CONFIGURATION"))
- local tradeRequestsFolder = rs:WaitForChild("TRADE REQUESTS")
- local ongoingTradesFolder = rs:WaitForChild("ONGOING TRADES")
- local gui = script.Parent
- local openBtn = gui:WaitForChild("OpenSendTrades")
- local sendTradesFrame = gui:WaitForChild("SendTradesFrame")
- local tradeRequestFrame = gui:WaitForChild("TradeRequestFrame")
- local tradeFrame = gui:WaitForChild("TradeFrame")
- sendTradesFrame.Visible = false
- tradeRequestFrame.Visible = false
- tradeFrame.Visible = false
- --TRADE REQUESTS
- tradeRequestsFolder.ChildAdded:Connect(function(child)
- if child.Value == client.Name then
- tradeRequestFrame.TradeText.Text = child.Name .. " sent you a trade request!"
- tradeRequestFrame.AcceptButton.Visible = true
- tradeRequestFrame.RejectButton.Visible = true
- tradeRequestFrame.Visible = true
- elseif child.Name == client.Name then
- tradeRequestFrame.TradeText.Text = "You sent a trade request to " .. child.Value
- tradeRequestFrame.AcceptButton.Visible = false
- tradeRequestFrame.RejectButton.Visible = true
- tradeRequestFrame.Visible = true
- end
- end)
- tradeRequestsFolder.ChildRemoved:Connect(function(child)
- if child.Value == client.Name or child.Name == client.Name then
- tradeRequestFrame.Visible = false
- end
- end)
- --ONGOING TRADES
- ongoingTradesFolder.ChildAdded:Connect(function(child)
- if child:WaitForChild("Sender").Value == client.Name or child:WaitForChild("Receiver").Value == client.Name then
- local clientValue = child:WaitForChild("Sender").Value == client.Name and child.Sender or child.Receiver
- local otherPlrValue = clientValue.Name == "Sender" and child.Receiver or child.Sender
- clientValue.AncestryChanged:Connect(function()
- if clientValue.Parent == nil then
- tradeFrame.Visible = false
- openBtn.Visible = true
- end
- end)
- tradeRequestFrame.Visible = false
- sendTradesFrame.Visible = false
- openBtn.Visible = false
- tradeFrame.TradingFrame.TradingWithName.Text = "Trading with " .. otherPlrValue.Value
- tradeFrame.TradingFrame.TheirOfferFrame.TheirOfferText.Text = otherPlrValue.Value .. "'s offer"
- tradeFrame.TradingFrame.PlayerAccepted.Text = ""
- tradeFrame.TradingFrame.AcceptButton.BackgroundColor3 = Color3.fromRGB(58, 191, 232)
- for i, child in pairs(tradeFrame.TradingFrame.YourOfferFrame:GetChildren()) do
- if child:IsA("TextButton") or child:IsA("ImageButton") or child:IsA("Frame") then
- child:Destroy()
- end
- end
- for i, child in pairs(tradeFrame.TradingFrame.TheirOfferFrame:GetChildren()) do
- if child:IsA("TextButton") or child:IsA("ImageButton") or child:IsA("Frame") then
- child:Destroy()
- end
- end
- --Alert client when other player has accepted
- otherPlrValue.ChildAdded:Connect(function(child)
- if child.Name == "ACCEPTED" then
- tradeFrame.TradingFrame.PlayerAccepted.Text = otherPlrValue.Value .. " has accepted"
- end
- end)
- otherPlrValue.ChildRemoved:Connect(function(child)
- if child.Name == "ACCEPTED" then
- tradeFrame.TradingFrame.PlayerAccepted.Text = ""
- end
- end)
- --Display player's inventory
- local inventoryList = tradeFrame.InventoryFrame.InventoryList
- for i, child in pairs(inventoryList:GetChildren()) do
- if child:IsA("TextButton") or child:IsA("ImageButton") then
- child:Destroy()
- end
- end
- local clientTools = config.GetTools(client)
- for i, tool in pairs(clientTools) do
- local newToolButton = script:WaitForChild("ItemButton"):Clone()
- newToolButton.Name = tool["TRADING ID"].Value
- newToolButton.ItemName.Text = tool.Name
- newToolButton.IsInTrade.Visible = false
- if string.len(tool.TextureId) > 0 then
- newToolButton.ItemViewportFrame.Visible = false
- newToolButton.ItemImageLabel.Image = tool.TextureId
- else
- newToolButton.ItemImageLabel.Visible = false
- local toolModel = Instance.new("Model")
- for x, descendant in pairs(tool:GetDescendants()) do
- if descendant:IsA("BasePart") then
- descendant:Clone().Parent = toolModel
- end
- end
- toolModel.PrimaryPart = toolModel:FindFirstChild("Handle") or toolModel:FindFirstChildOfClass("BasePart", true)
- toolModel:SetPrimaryPartCFrame(CFrame.new(0, 0, -3))
- toolModel.Parent = newToolButton.ItemViewportFrame
- local vpfCamera = Instance.new("Camera")
- vpfCamera.CFrame = CFrame.new()
- vpfCamera.Parent = newToolButton.ItemViewportFrame
- end
- newToolButton.MouseButton1Click:Connect(function()
- if not tradeFrame.TradingFrame.YourOfferFrame.Slots:FindFirstChild(tool["TRADING ID"].Value) then
- newToolButton.IsInTrade.Visible = true
- re:FireServer("add item to trade", {tool})
- else
- newToolButton.IsInTrade.Visible = false
- re:FireServer("remove item from trade", {tool})
- end
- end)
- newToolButton.Parent = inventoryList
- end
- --Display client's offer
- local clientOffer = child[clientValue.Value .. "'s offer"]
- clientOffer.ChildAdded:Connect(function(child)
- local newToolButton = inventoryList[child:WaitForChild("TRADING ID").Value]:Clone()
- newToolButton.IsInTrade.Visible = false
- newToolButton.Size = script.ItemButton.Size
- newToolButton.MouseButton1Click:Connect(function()
- local plrTools = config.GetTools(client)
- for i, plrTool in pairs(plrTools) do
- if child["TRADING ID"].Value == plrTool["TRADING ID"].Value then
- re:FireServer("remove item from trade", {plrTool})
- break
- end
- end
- end)
- child.AncestryChanged:Connect(function()
- if child.Parent == nil then
- tradeFrame.InventoryFrame.InventoryList[newToolButton.Name].IsInTrade.Visible = false
- newToolButton:Destroy()
- end
- end)
- newToolButton.Parent = tradeFrame.TradingFrame.YourOfferFrame.Slots
- end)
- --Display other player's offer
- local otherPlrOffer = child[otherPlrValue.Value .. "'s offer"]
- otherPlrOffer.ChildAdded:Connect(function(child)
- local newToolButton = script.ItemButton:Clone()
- newToolButton.Name = child:WaitForChild("TRADING ID").Value
- newToolButton.ItemName.Text = child.Name
- newToolButton.IsInTrade.Visible = false
- newToolButton.AutoButtonColor = false
- if string.len(child.TextureId) > 0 then
- newToolButton.ItemViewportFrame.Visible = false
- newToolButton.ItemImageLabel.Image = child.TextureId
- else
- newToolButton.ItemImageLabel.Visible = false
- local toolModel = Instance.new("Model")
- for x, descendant in pairs(child:GetDescendants()) do
- if descendant:IsA("BasePart") then
- descendant:Clone().Parent = toolModel
- end
- end
- toolModel.PrimaryPart = toolModel:FindFirstChild("Handle") or toolModel:FindFirstChildOfClass("BasePart", true)
- toolModel:SetPrimaryPartCFrame(CFrame.new(0, 0, -3))
- toolModel.Parent = newToolButton.ItemViewportFrame
- local vpfCamera = Instance.new("Camera")
- vpfCamera.CFrame = CFrame.new()
- vpfCamera.Parent = newToolButton.ItemViewportFrame
- end
- child.AncestryChanged:Connect(function()
- if child.Parent == nil then
- newToolButton:Destroy()
- end
- end)
- newToolButton.Parent = tradeFrame.TradingFrame.TheirOfferFrame.Slots
- end)
- tradeFrame.Visible = true
- end
- end)
- --SEND TRADE REQUESTS
- openBtn.MouseButton1Click:Connect(function()
- if sendTradesFrame.Visible == true then
- sendTradesFrame.Visible = false
- elseif tradeFrame.Visible == false then
- for i, child in pairs(sendTradesFrame.PlayerList:GetChildren()) do
- if child:IsA("Frame") then
- child:Destroy()
- end
- end
- for i, plr in pairs(game.Players:GetPlayers()) do
- if plr ~= client then
- local playerFrame = script:WaitForChild("PlayerFrame"):Clone()
- playerFrame.PlayerDisplayName.Text = plr.DisplayName
- playerFrame.PlayerUserName.Text = "@" .. plr.Name
- playerFrame.PlayerImage.Image = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
- playerFrame.SendButton.MouseButton1Click:Connect(function()
- if tradeRequestFrame.Visible == false then
- re:FireServer("send trade request", {plr})
- end
- end)
- playerFrame.Parent = sendTradesFrame.PlayerList
- end
- end
- sendTradesFrame.Visible = true
- end
- end)
- sendTradesFrame.CloseButton.MouseButton1Click:Connect(function()
- sendTradesFrame.Visible = false
- end)
- --ACCEPT OR REJECT TRADE REQUESTS
- tradeRequestFrame.RejectButton.MouseButton1Click:Connect(function()
- re:FireServer("reject trade request")
- end)
- tradeRequestFrame.AcceptButton.MouseButton1Click:Connect(function()
- re:FireServer("accept trade request")
- end)
- --ACCEPT OR REJECT TRADES
- tradeFrame.TradingFrame.RejectButton.MouseButton1Click:Connect(function()
- re:FireServer("reject trade")
- end)
- tradeFrame.TradingFrame.AcceptButton.MouseButton1Click:Connect(function()
- re:FireServer("accept trade")
- if tradeFrame.TradingFrame.AcceptButton.BackgroundColor3 == Color3.fromRGB(58, 191, 232) then
- tradeFrame.TradingFrame.AcceptButton.BackgroundColor3 = Color3.fromRGB(40, 109, 152)
- else
- tradeFrame.TradingFrame.AcceptButton.BackgroundColor3 = Color3.fromRGB(58, 191, 232)
- end
- end)
Add Comment
Please, Sign In to add comment