-- TradeWindow: "Обмен" between two players on the server (frame, tabs, buttons: ShopKit). -- Tabs: Игроки / Сделка / Как это работает. "Сделка" gets a badge while a trade is open. -- Игроки : one row per player with level; button: ready "Предложить обмен", off when a level is too low, -- info "Запрос отправлен" for a while after sending. -- Сделка : two columns (you / them): offered toys, value, ready status; your shards stepper and your toys -- (click adds, click on an offered toy removes, fresh toys locked). Buttons: Готов <-> Не готов, -- Подтвердить (off until both are ready and the countdown ends, then ready; "Ждём второго" after it), -- Отменить. A warning shows when one side is worth much more. -- The incoming request is a small popup on top of the screen (Принять / Отклонить + timer bar). -- RemoteEvent "Trade": Request / Respond / SetShards / AddItem / RemoveItem / Ready / Confirm / Cancel; -- server -> client: Incoming / State / Closed. local Players = game:GetService("Players") local K = require(script.Parent:WaitForChild("ShopKit")) local T = {} local WHITE, GOLD, SOFT, OK, WARN, BODY, NAVY = K.WHITE, K.GOLD, K.SOFT, K.OK, K.WARN, K.BODY, K.NAVY local new, corner, art, label, maxText, pill, tween = K.new, K.corner, K.art, K.label, K.maxText, K.pill, K.tween local PANEL = Color3.new(0, 0, 0) function T.install(ctx) local Config, player, remote = ctx.Config, ctx.player, ctx.remote local TR = Config.TRADE local fmt = ctx.fmtNum local function attr(n, d) local v = player:GetAttribute(n); if v == nil then return d end return v end local win = ctx.win local TAX = math.floor(TR.TAX * 100 + 0.5) local state, lastTheirs = nil, {} local refresh, render local TABS = { { id = "Players", text = "Players", icon = "👥", tip = "Trading unlocks at level " .. TR.MIN_LEVEL .. " for both players." }, { id = "Deal", text = "Deal", icon = "🤝", tip = "Any change clears “Ready” for both players — so nobody can swap an ornament at the last moment." }, { id = "Help", text = "How It Works", icon = "📖", tip = "Tax " .. TAX .. "% applies only to shards sent; ornaments are tax-free." }, } local ch = K.chrome({ win = win, title = "TRADE", subtitle = "Trade ornaments\nwith players on this server", tabs = TABS, closeWindow = function() if state then remote:FireServer("Cancel") end ctx.closeWindow() end, fmtNum = fmt, onTab = function() if win.overlay.Visible then refresh() end end }) local function darkPanel(parent, pos, size, z) return new("Frame", { Position = pos, Size = size, BackgroundColor3 = PANEL, BackgroundTransparency = 0.5, ZIndex = z or 4, Parent = parent }, { corner(UDim.new(0, 22)), new("UIStroke", { Color = GOLD, Thickness = 2, Transparency = 0.4 }), }) end local function statusChip(parent, pos) local f = new("Frame", { AnchorPoint = Vector2.new(1, 0.5), Position = pos, Size = UDim2.fromOffset(150, 38), BackgroundColor3 = Color3.fromRGB(70, 82, 100), ZIndex = 6, Parent = parent }, { corner(UDim.new(0.5, 0)), new("UIStroke", { Color = WHITE, Thickness = 2, Transparency = 0.5 }), }) local t = maxText(label({ Position = UDim2.fromOffset(8, 5), Size = UDim2.new(1, -16, 1, -10), Text = "", TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 7, Parent = f }, 1.5), 22) return function(side) local s = side.confirmed and "confirmed" or side.ready and "ready" or "not ready" t.Text = s f.BackgroundColor3 = side.confirmed and Color3.fromRGB(200, 140, 30) or side.ready and Color3.fromRGB(40, 150, 80) or Color3.fromRGB(70, 82, 100) end end local function tileGrid(parent, pos, size) local s = K.scroll(parent, pos, size, new("UIGridLayout", { CellSize = UDim2.fromOffset(112, 150), CellPadding = UDim2.fromOffset(8, 8), SortOrder = Enum.SortOrder.LayoutOrder })) new("UIPadding", { PaddingLeft = UDim.new(0, 10), PaddingTop = UDim.new(0, 12), PaddingBottom = UDim.new(0, 8), Parent = s }) return s end local function clear(f) for _, c in f:GetChildren() do if c:IsA("GuiObject") then c:Destroy() end end end ---------------------------------------------------------------- players local _, plScroll = ch.makePage("Players", true) new("UIListLayout", { Padding = UDim.new(0, 12), SortOrder = Enum.SortOrder.LayoutOrder, Parent = plScroll }) new("UIPadding", { PaddingLeft = UDim.new(0, 4), PaddingRight = UDim.new(0, 18), PaddingTop = UDim.new(0, 4), PaddingBottom = UDim.new(0, 4), Parent = plScroll }) local requested = {} -- userId -> os.clock() of my request local function rebuildPlayers() clear(plScroll) local myLvl = attr("Level", 1) local n = 0 for _, p in Players:GetPlayers() do if p ~= player then n += 1 local lvl = p:GetAttribute("Level") or 1 local row = new("Frame", { Size = UDim2.new(1, 0, 0, 112), BackgroundColor3 = PANEL, BackgroundTransparency = 0.45, LayoutOrder = n, ZIndex = 5, Parent = plScroll }, { corner(UDim.new(0, 26)), new("UIStroke", { Color = GOLD, Thickness = 2, Transparency = 0.3 }), }) local face = new("ImageLabel", { Position = UDim2.fromOffset(14, 10), Size = UDim2.fromOffset(92, 92), BackgroundColor3 = NAVY, Image = "", ZIndex = 6, Parent = row }, { corner(UDim.new(0.5, 0)), new("UIStroke", { Color = GOLD, Thickness = 3 }), }) task.spawn(function() local ok, img = pcall(Players.GetUserThumbnailAsync, Players, p.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150) if ok and face.Parent then face.Image = img end end) maxText(label({ Position = UDim2.fromOffset(124, 14), Size = UDim2.fromOffset(640, 44), Text = p.DisplayName, TextScaled = true, ZIndex = 6, Parent = row }, 2.5), 36) maxText(label({ Position = UDim2.fromOffset(126, 60), Size = UDim2.fromOffset(640, 30), Text = "@" .. p.Name .. " · level " .. lvl, TextScaled = true, FontFace = BODY, TextColor3 = lvl >= TR.MIN_LEVEL and OK or SOFT, ZIndex = 6, Parent = row }, 1.5), 22) local btn btn = pill(row, { Position = UDim2.fromOffset(880, 20), Size = UDim2.fromOffset(330, 72), ZIndex = 6, TextMax = 28 }, function() requested[p.UserId] = os.clock() remote:FireServer("Request", p) ctx.toast("Request sent: " .. p.DisplayName, OK) rebuildPlayers() end) if state then btn.set("info", "You are already trading") elseif requested[p.UserId] and os.clock() - requested[p.UserId] < 15 then btn.set("info", "Request sent") elseif myLvl < TR.MIN_LEVEL then btn.set("off", "Level " .. TR.MIN_LEVEL .. "+") elseif lvl < TR.MIN_LEVEL then btn.set("off", "Player is level " .. lvl) else btn.set("ready", "Offer a trade") end end end if n == 0 then local e = K.emptyState({ Size = UDim2.new(1, 0, 0, 500), ZIndex = 5, Parent = plScroll }, "Nobody else is on this server", "Invite a friend — trading works between players on the same server.") e.LayoutOrder = 1 end end Players.PlayerAdded:Connect(function() if win.overlay.Visible and ch.current() == "Players" then rebuildPlayers() end end) Players.PlayerRemoving:Connect(function() task.defer(function() if win.overlay.Visible and ch.current() == "Players" then rebuildPlayers() end end) end) ---------------------------------------------------------------- deal local dealG = ch.makePage("Deal") local noDeal = K.emptyState({ Position = UDim2.fromOffset(0, 60), Size = UDim2.new(1, 0, 0, 420), ZIndex = 5, Parent = dealG }, "No active trade", "Pick a player in the “Players” tab and offer a trade — or accept someone's request.") local pickBtn = pill(noDeal, { Position = UDim2.new(0.5, -160, 0, 320), Size = UDim2.fromOffset(320, 66), ZIndex = 6, TextMax = 28 }, function() ch.showTab("Players") end) pickBtn.set("alt", "Pick a player") local deal = new("Frame", { Size = UDim2.fromScale(1, 1), BackgroundTransparency = 1, Visible = false, ZIndex = 4, Parent = dealG }) -- left: me local myHead = darkPanel(deal, UDim2.fromOffset(0, 0), UDim2.fromOffset(620, 56)) maxText(label({ Position = UDim2.fromOffset(18, 8), Size = UDim2.fromOffset(240, 40), Text = "You give", TextScaled = true, ZIndex = 6, Parent = myHead }, 2.5), 30) local myValue = maxText(label({ Position = UDim2.fromOffset(260, 12), Size = UDim2.fromOffset(186, 32), Text = "", TextScaled = true, FontFace = BODY, TextColor3 = Color3.fromRGB(190, 225, 255), TextXAlignment = Enum.TextXAlignment.Right, ZIndex = 6, Parent = myHead }, 1.5), 22) local myChip = statusChip(myHead, UDim2.new(1, -10, 0.5, 0)) local myOffer = darkPanel(deal, UDim2.fromOffset(0, 62), UDim2.fromOffset(620, 190)) local myGrid = tileGrid(myOffer, UDim2.new(), UDim2.fromScale(1, 1)) local myHint = maxText(label({ Position = UDim2.fromOffset(20, 70), Size = UDim2.new(1, -40, 0, 50), Text = "Click one of your ornaments below to put it here", TextScaled = true, TextWrapped = true, FontFace = BODY, TextColor3 = SOFT, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = myOffer }, 1.5), 22) maxText(label({ Position = UDim2.fromOffset(6, 268), Size = UDim2.fromOffset(130, 40), Text = "Shards", TextScaled = true, ZIndex = 5, Parent = deal }, 2), 28) local boxWrap = new("Frame", { Position = UDim2.fromOffset(206, 260), Size = UDim2.fromOffset(180, 56), BackgroundColor3 = NAVY, ZIndex = 5, Parent = deal }, { corner(UDim.new(0.5, 0)), new("UIStroke", { Color = Color3.fromRGB(190, 225, 255), Thickness = 2 }), }) art("crystal", { Position = UDim2.new(0, -8, 0.5, -28), Size = UDim2.fromOffset(56, 56), ZIndex = 6, Parent = boxWrap }) local shardBox = new("TextBox", { Position = UDim2.fromOffset(46, 6), Size = UDim2.new(1, -60, 1, -12), BackgroundTransparency = 1, Text = "0", PlaceholderText = "0", ClearTextOnFocus = false, FontFace = K.FONT, TextScaled = true, TextColor3 = WHITE, ZIndex = 6, Parent = boxWrap }) maxText(shardBox, 32) local function sendShards(n) remote:FireServer("SetShards", math.clamp(math.floor(n or tonumber(shardBox.Text) or 0), 0, attr("Shards", 0))) end local minus = pill(deal, { Position = UDim2.fromOffset(136, 260), Size = UDim2.fromOffset(62, 56), ZIndex = 5, TextMax = 36 }, function() sendShards((state and state.me.shards or 0) - 10) end) local plus = pill(deal, { Position = UDim2.fromOffset(394, 260), Size = UDim2.fromOffset(62, 56), ZIndex = 5, TextMax = 36 }, function() sendShards((state and state.me.shards or 0) + 10) end) minus.set("alt", "-") plus.set("alt", "+") local setBtn = pill(deal, { Position = UDim2.fromOffset(464, 260), Size = UDim2.fromOffset(156, 56), ZIndex = 5, TextMax = 26 }, function() sendShards() end) setBtn.set("alt", "Set") shardBox:GetPropertyChangedSignal("Text"):Connect(function() local d = shardBox.Text:gsub("%D", "") if d ~= shardBox.Text then shardBox.Text = d end end) shardBox.FocusLost:Connect(function(enter) if enter then sendShards() end end) local myShardNote = maxText(label({ Position = UDim2.fromOffset(6, 320), Size = UDim2.fromOffset(614, 26), Text = "", TextScaled = true, FontFace = BODY, TextColor3 = SOFT, ZIndex = 5, Parent = deal }, 1.5), 19) local invPanel = darkPanel(deal, UDim2.fromOffset(0, 352), UDim2.fromOffset(620, 214)) maxText(label({ Position = UDim2.fromOffset(16, 6), Size = UDim2.fromOffset(590, 28), Text = "Your ornaments — click to add", TextScaled = true, FontFace = BODY, TextColor3 = SOFT, ZIndex = 5, Parent = invPanel }, 1.5), 20) local invGrid = tileGrid(invPanel, UDim2.fromOffset(0, 34), UDim2.new(1, 0, 1, -38)) -- right: them local thHead = darkPanel(deal, UDim2.fromOffset(640, 0), UDim2.fromOffset(620, 56)) local thTitle = maxText(label({ Position = UDim2.fromOffset(18, 8), Size = UDim2.fromOffset(250, 40), Text = "", TextScaled = true, ZIndex = 6, Parent = thHead }, 2.5), 30) local thValue = maxText(label({ Position = UDim2.fromOffset(270, 12), Size = UDim2.fromOffset(176, 32), Text = "", TextScaled = true, FontFace = BODY, TextColor3 = Color3.fromRGB(190, 225, 255), TextXAlignment = Enum.TextXAlignment.Right, ZIndex = 6, Parent = thHead }, 1.5), 22) local thChip = statusChip(thHead, UDim2.new(1, -10, 0.5, 0)) local thOffer = darkPanel(deal, UDim2.fromOffset(640, 62), UDim2.fromOffset(620, 190)) local thGrid = tileGrid(thOffer, UDim2.new(), UDim2.fromScale(1, 1)) local thHint = maxText(label({ Position = UDim2.fromOffset(20, 70), Size = UDim2.new(1, -40, 0, 50), Text = "Nothing added yet", TextScaled = true, FontFace = BODY, TextColor3 = SOFT, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = thOffer }, 1.5), 22) local thShards = new("Frame", { Position = UDim2.fromOffset(640, 260), Size = UDim2.fromOffset(620, 56), BackgroundColor3 = NAVY, ZIndex = 5, Parent = deal }, { corner(UDim.new(0.5, 0)), new("UIStroke", { Color = Color3.fromRGB(190, 225, 255), Thickness = 2 }), }) art("crystal", { Position = UDim2.new(0, -6, 0.5, -28), Size = UDim2.fromOffset(56, 56), ZIndex = 6, Parent = thShards }) local thShardsText = maxText(label({ Position = UDim2.fromOffset(58, 8), Size = UDim2.new(1, -72, 1, -16), Text = "", TextScaled = true, ZIndex = 6, Parent = thShards }, 2), 28) local warnText = maxText(label({ Position = UDim2.fromOffset(640, 324), Size = UDim2.fromOffset(620, 40), Text = "", TextScaled = true, TextWrapped = true, TextColor3 = WARN, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = deal }, 1.5), 22) local stepText = maxText(label({ Position = UDim2.fromOffset(640, 368), Size = UDim2.fromOffset(620, 48), Text = "", TextScaled = true, TextColor3 = GOLD, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = deal }, 2.5), 34) local readyBtn = pill(deal, { Position = UDim2.fromOffset(640, 440), Size = UDim2.fromOffset(196, 84), ZIndex = 5, TextMax = 30 }, function() if state then remote:FireServer("Ready", not state.me.ready) end end) local confirmBtn -- declared first: the click callback below refers to it confirmBtn = pill(deal, { Position = UDim2.fromOffset(842, 440), Size = UDim2.fromOffset(216, 84), ZIndex = 5, TextMax = 28 }, function() if state and state.canConfirm then confirmBtn.set("busy"); remote:FireServer("Confirm") end end) local cancelBtn = pill(deal, { Position = UDim2.fromOffset(1064, 440), Size = UDim2.fromOffset(196, 84), ZIndex = 5, TextMax = 30 }, function() remote:FireServer("Cancel") end) cancelBtn.set("danger", "Cancel") local function stepLine() local me, them = state.me, state.them if state.countdown and state.countdown > 0 then return "Confirm in " .. math.ceil(state.countdown) .. "s" end if me.confirmed then return "Waiting for " .. them.name .. " to confirm" end if state.canConfirm then return "All set — confirm!" end if me.ready and not them.ready then return "Waiting for " .. them.name .. " to press “Ready”" end if not me.ready then return "Check both offers and press “Ready”" end return "" end render = function() ch.tabs.Deal.setBadge(state and 1 or 0) noDeal.Visible = state == nil deal.Visible = state ~= nil if not state then return end local me, them = state.me, state.them myValue.Text = "value " .. fmt(me.value) thValue.Text = "value " .. fmt(them.value) thTitle.Text = them.name .. " gives" myChip(me) thChip(them) -- my offer (click removes) clear(myGrid) local inOffer = {} for k, it in me.items do inOffer[it.uid] = true local t = K.toyTile({ Config = Config, miniPattern = ctx.miniPattern, parent = myGrid, item = it, w = 112, h = 150, order = k, z = 6, value = true }) t.button.Activated:Connect(function() remote:FireServer("RemoveItem", it.uid) end) end myHint.Visible = #me.items == 0 -- their offer (new items marked) clear(thGrid) local now = {} for k, it in them.items do now[it.uid] = true local t = K.toyTile({ Config = Config, miniPattern = ctx.miniPattern, parent = thGrid, item = it, w = 112, h = 150, order = k, z = 6, value = true, inert = true }) if not lastTheirs[it.uid] then t.setSelected(true) local tag = new("Frame", { AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, -10), Size = UDim2.fromOffset(84, 24), BackgroundColor3 = GOLD, ZIndex = 12, Parent = t.button }, { corner(UDim.new(0.5, 0)) }) maxText(label({ Position = UDim2.fromOffset(4, 2), Size = UDim2.new(1, -8, 1, -4), Text = "NEW", TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 13, Parent = tag }, 1.5), 18) end end lastTheirs = now thHint.Visible = #them.items == 0 -- shards if not shardBox:IsFocused() then shardBox.Text = tostring(me.shards) end myShardNote.Text = me.shards > 0 and ("arrives: " .. fmt(math.floor(me.shards * (1 - TR.TAX))) .. " after " .. TAX .. "% · you have " .. fmt(attr("Shards", 0))) or ("you have " .. fmt(attr("Shards", 0)) .. " shards") thShardsText.Text = them.shards > 0 and ("+" .. fmt(math.floor(them.shards * (1 - TR.TAX))) .. " shards to you (after tax)") or "offers no shards" -- my toys clear(invGrid) local inv = player:FindFirstChild("OrnamentInventory") local list = {} for _, c in inv and inv:GetChildren() or {} do if not inOffer[c.Name] and not c:GetAttribute("OnTree") then table.insert(list, c) end end table.sort(list, function(x, y) local rx, ry = Config.RarityById[x:GetAttribute("Rarity")], Config.RarityById[y:GetAttribute("Rarity")] if rx.Index ~= ry.Index then return rx.Index > ry.Index end return (x:GetAttribute("Order") or 0) > (y:GetAttribute("Order") or 0) end) local full = #me.items >= TR.MAX_ITEMS for k, c in list do local it = { Toy = c:GetAttribute("Toy"), Rarity = c:GetAttribute("Rarity"), Variant = c:GetAttribute("Variant") } local t = K.toyTile({ Config = Config, miniPattern = ctx.miniPattern, parent = invGrid, item = it, w = 112, h = 150, order = k, z = 6, value = true }) local age = os.time() - (c:GetAttribute("Created") or 0) if age < TR.MIN_AGE then t.lock("🔒\n" .. math.ceil((TR.MIN_AGE - age) / 60) .. " min") t.button.Activated:Connect(function() t.wiggle(); ctx.toast("New ornaments can be traded in " .. (TR.MIN_AGE // 60) .. " min", WARN) end) else t.button.Activated:Connect(function() if full then t.wiggle(); ctx.toast("No more than " .. TR.MAX_ITEMS .. " ornaments per trade", WARN) return end remote:FireServer("AddItem", c.Name) end) end end -- warning + step + buttons local hi, lo = math.max(me.value, them.value), math.min(me.value, them.value) if (me.value > 0 or them.value > 0) and (lo == 0 or hi / lo > TR.WARN_RATIO) then warnText.Text = me.value > them.value and "Warning: you're giving much more than you get!" or "You're getting much more — make sure it's fair." else warnText.Text = "" end stepText.Text = stepLine() if me.confirmed then readyBtn.set("off", "Ready") elseif me.ready then readyBtn.set("alt", "Not ready") else readyBtn.set("ready", "Ready") end if me.confirmed then confirmBtn.set("done", "Confirmed") elseif state.canConfirm then confirmBtn.set("ready", "Confirm") elseif state.countdown and state.countdown > 0 then confirmBtn.set("off", "In " .. math.ceil(state.countdown) .. "s") else confirmBtn.set("off", "Press “Ready” first") end end ---------------------------------------------------------------- help local _, heScroll = ch.makePage("Help", true) new("UIGridLayout", { CellSize = UDim2.fromOffset(404, 540), CellPadding = UDim2.fromOffset(20, 18), SortOrder = Enum.SortOrder.LayoutOrder, Parent = heScroll }) new("UIPadding", { PaddingLeft = UDim.new(0, 4), PaddingTop = UDim.new(0, 4), Parent = heScroll }) local HELP = { { card = "cardCyan", icon = "👥", title = "1. Invite", tab = "Players", text = "Pick a player and offer a trade. Both need level " .. TR.MIN_LEVEL .. ". New ornaments can be traded " .. (TR.MIN_AGE // 60) .. " min after they are made." }, { card = "cardViolet", icon = "🎁", title = "2. Add", tab = "Deal", text = "Up to " .. TR.MAX_ITEMS .. " ornaments and shards (tax " .. TAX .. "%). Click your ornament to add it, click an added one to remove it." }, { card = "cardOrange", icon = "🤝", title = "3. Confirm", tab = "Deal", text = "Both press “Ready”, then after " .. TR.COUNTDOWN .. "s — “Confirm”. Any change clears “Ready” for both." }, } for i, h in HELP do local card = art(h.card, { LayoutOrder = i, ScaleType = Enum.ScaleType.Slice, SliceCenter = K.CARD_SLICE, ZIndex = 4, Parent = heScroll }) label({ AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 44), Size = UDim2.fromOffset(120, 110), Text = h.icon, TextSize = 84, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 0) maxText(label({ Position = UDim2.fromOffset(24, 160), Size = UDim2.new(1, -48, 0, 50), Text = h.title, TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 3), 42) maxText(label({ Position = UDim2.fromOffset(30, 218), Size = UDim2.new(1, -60, 0, 190), Text = h.text, TextScaled = true, TextWrapped = true, FontFace = BODY, TextColor3 = WHITE, TextXAlignment = Enum.TextXAlignment.Center, TextYAlignment = Enum.TextYAlignment.Top, ZIndex = 5, Parent = card }, 1.5), 24) local go = pill(card, { Position = UDim2.fromOffset(62, 420), Size = UDim2.fromOffset(280, 70), ZIndex = 5, TextMax = 30 }, function() ch.showTab(h.tab) end) go.set("alt", "Open") end refresh = function() ch.setBalance(attr("Shards", 0)) if ch.current() == "Players" then rebuildPlayers() elseif ch.current() == "Deal" then render() end if attr("Level", 1) < TR.MIN_LEVEL and ch.current() ~= "Help" then ch.tip.Text = "🔒 Trading unlocks at level " .. TR.MIN_LEVEL .. " — you are level " .. attr("Level", 1) .. "." ch.tip.TextColor3 = WARN end end ---------------------------------------------------------------- incoming request popup local popup = new("Frame", { Name = "TradeRequest", AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 16), Size = UDim2.fromOffset(470, 150), BackgroundColor3 = WHITE, Visible = false, ZIndex = 40, Parent = ctx.gui }, { corner(UDim.new(0, 22)), new("UIGradient", { Rotation = 90, Color = ColorSequence.new(Color3.fromRGB(22, 84, 70), Color3.fromRGB(8, 36, 44)) }), new("UIStroke", { Color = Color3.fromRGB(242, 196, 82), Thickness = 3 }), }) local popScale = new("UIScale", { Parent = popup }) label({ Position = UDim2.fromOffset(14, 12), Size = UDim2.fromOffset(56, 56), Text = "🤝", TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 41, Parent = popup }, 0) local popText = maxText(label({ Position = UDim2.fromOffset(80, 12), Size = UDim2.fromOffset(376, 56), Text = "", TextScaled = true, TextWrapped = true, ZIndex = 41, Parent = popup }, 2), 24) local popBarBg = new("Frame", { Position = UDim2.fromOffset(16, 74), Size = UDim2.new(1, -32, 0, 8), BackgroundColor3 = Color3.fromRGB(10, 20, 26), ZIndex = 41, Parent = popup }, { corner(UDim.new(0.5, 0)) }) local popBar = new("Frame", { Size = UDim2.fromScale(1, 1), BackgroundColor3 = GOLD, ZIndex = 42, Parent = popBarBg }, { corner(UDim.new(0.5, 0)) }) local pendingFrom local function closePopup() popup.Visible = false; pendingFrom = nil end local accept = pill(popup, { Position = UDim2.fromOffset(16, 90), Size = UDim2.fromOffset(212, 50), ZIndex = 41, TextMax = 24 }, function() if pendingFrom then remote:FireServer("Respond", pendingFrom, true) end closePopup() end) local decline = pill(popup, { Position = UDim2.fromOffset(242, 90), Size = UDim2.fromOffset(212, 50), ZIndex = 41, TextMax = 24 }, function() if pendingFrom then remote:FireServer("Respond", pendingFrom, false) end closePopup() end) accept.set("ready", "Accept") decline.set("danger", "Decline") ---------------------------------------------------------------- server events remote.OnClientEvent:Connect(function(kind, data) if kind == "Incoming" then pendingFrom = data.from popText.Text = data.name .. " (lvl " .. data.level .. ") wants to trade" popup.Visible = true popScale.Scale = 0.85 tween(popScale, 0.25, { Scale = 1 }, Enum.EasingStyle.Back) popBar.Size = UDim2.fromScale(1, 1) tween(popBar, data.ttl, { Size = UDim2.fromScale(0, 1) }, Enum.EasingStyle.Linear) local mine = pendingFrom task.delay(data.ttl, function() if pendingFrom == mine then closePopup() end end) elseif kind == "State" then local first = state == nil state = data if first then lastTheirs = {} for _, it in data.them.items do lastTheirs[it.uid] = true end requested = {} end if not win.overlay.Visible then ctx.openWindow() end if ch.current() ~= "Deal" then ch.showTab("Deal") else render() end elseif kind == "Closed" then state = nil lastTheirs = {} render() if win.overlay.Visible then ctx.closeWindow() end if data then ctx.toast(data, WARN) end end end) -- local countdown tick (the server re-sends the state when the countdown ends) task.spawn(function() while true do task.wait(0.25) if state and state.countdown and state.countdown > 0 and win.overlay.Visible then state.countdown = math.max(0, state.countdown - 0.25) stepText.Text = stepLine() if not state.me.confirmed and not state.canConfirm then confirmBtn.set("off", "In " .. math.ceil(state.countdown) .. "s") end end end end) task.spawn(function() local inv = player:WaitForChild("OrnamentInventory") local function changed() if state and win.overlay.Visible then task.defer(render) end end inv.ChildAdded:Connect(changed) inv.ChildRemoved:Connect(changed) end) player:GetAttributeChangedSignal("Shards"):Connect(function() if win.overlay.Visible then ch.setBalance(attr("Shards", 0)) end end) ch.showTab("Players") return { open = function() ch.setBalance(attr("Shards", 0), true) local want = state and "Deal" or ch.current() if want ~= ch.current() then ch.showTab(want) else refresh() end end, active = function() return state ~= nil end, showTab = ch.showTab, } end return T