Загрузка данных


-- ТИП: LocalScript
-- МЕСТО: StarterPlayer > StarterPlayerScripts
-- ИМЯ: MainUI
-- Кнопки Shop / Home / Sell справа + деньги слева снизу. БЕЗ чёрной подложки.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Принимает "123456789" или "rbxassetid://123456789"; пока ID не вставлен — иконка пустая
local function toImage(id)
	id = tostring(id)
	if tonumber(id) then
		return "rbxassetid://" .. id
	elseif id:find("rbxassetid://", 1, true) then
		return id
	end
	return ""
end

local remote = ReplicatedStorage:WaitForChild("UIAction")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local gui = Instance.new("ScreenGui")
gui.Name = "MainUI"
gui.ResetOnSpawn = false
gui.IgnoreGuiInset = true
gui.Parent = player:WaitForChild("PlayerGui")

-- Масштаб под экран телефона
local function bindScale(scaleObj)
	local function update()
		local h = camera.ViewportSize.Y
		scaleObj.Scale = math.clamp(h / 800, 0.6, 1.3)
	end
	update()
	camera:GetPropertyChangedSignal("ViewportSize"):Connect(update)
end

------------------------------------------------------------
-- Кнопки справа
------------------------------------------------------------
local BTN_W, BTN_H = 84, 82
local ICON = 64

local sideFrame = Instance.new("Frame")
sideFrame.Name = "SideButtons"
sideFrame.BackgroundTransparency = 1
sideFrame.AnchorPoint = Vector2.new(1, 0)
sideFrame.Position = UDim2.new(1, -14, 0.1, 0)
sideFrame.Size = UDim2.fromOffset(BTN_W, BTN_H * 3 + 24)
sideFrame.Parent = gui

local sideScale = Instance.new("UIScale")
sideScale.Parent = sideFrame
bindScale(sideScale)

local list = Instance.new("UIListLayout")
list.FillDirection = Enum.FillDirection.Vertical
list.Padding = UDim.new(0, 12)
list.SortOrder = Enum.SortOrder.LayoutOrder
list.HorizontalAlignment = Enum.HorizontalAlignment.Center
list.Parent = sideFrame

local function createSideButton(name, text, image, order)
	local btn = Instance.new("TextButton")
	btn.Name = name
	btn.Text = ""
	btn.AutoButtonColor = false
	btn.BackgroundTransparency = 1 -- никакой подложки
	btn.BorderSizePixel = 0
	btn.Size = UDim2.fromOffset(BTN_W, BTN_H)
	btn.LayoutOrder = order
	btn.Parent = sideFrame

	local icon = Instance.new("ImageLabel")
	icon.Name = "Icon"
	icon.BackgroundTransparency = 1
	icon.Image = toImage(image)
	icon.ScaleType = Enum.ScaleType.Fit
	icon.AnchorPoint = Vector2.new(0.5, 0)
	icon.Position = UDim2.new(0.5, 0, 0, 0)
	icon.Size = UDim2.fromOffset(ICON, ICON)
	icon.Parent = btn

	-- Текст: центр лежит на нижней границе иконки (половина на ней, половина под ней)
	local label = Instance.new("TextLabel")
	label.Name = "Label"
	label.BackgroundTransparency = 1
	label.AnchorPoint = Vector2.new(0.5, 0.5)
	label.Position = UDim2.new(0.5, 0, 0, ICON)
	label.Size = UDim2.new(1, 0, 0, 24)
	label.Font = Enum.Font.GothamBold
	label.Text = text
	label.TextSize = 20
	label.TextColor3 = Color3.fromRGB(255, 255, 255)
	label.ZIndex = 2
	label.Parent = btn

	-- Обводка самого текста (чтобы читался на любом фоне), не подложка
	local stroke = Instance.new("UIStroke")
	stroke.Thickness = 2
	stroke.Color = Color3.fromRGB(0, 0, 0)
	stroke.Parent = label

	-- Небольшая анимация нажатия
	local iconScale = Instance.new("UIScale")
	iconScale.Parent = icon
	btn.MouseButton1Down:Connect(function() iconScale.Scale = 0.9 end)
	btn.MouseButton1Up:Connect(function() iconScale.Scale = 1 end)
	btn.MouseLeave:Connect(function() iconScale.Scale = 1 end)

	return btn
end

-- ============ ВСТАВЛЯЙ АЙДИ ИКОНОК СЮДА (третий параметр) ============
-- Можно писать просто цифры: "123456789"
local shopBtn = createSideButton("Shop", "Shop", "ВСТАВЬ_ID_SHOP", 1)
local homeBtn = createSideButton("Home", "Home", "ВСТАВЬ_ID_HOME", 2)
local sellBtn = createSideButton("Sell", "Sell", "ВСТАВЬ_ID_SELL", 3)
-- =====================================================================

shopBtn.Activated:Connect(function() remote:FireServer("Shop") end)
homeBtn.Activated:Connect(function() remote:FireServer("Home") end)
sellBtn.Activated:Connect(function() remote:FireServer("Sell") end)

------------------------------------------------------------
-- Деньги (слева снизу), без подложки
------------------------------------------------------------
local cashFrame = Instance.new("Frame")
cashFrame.Name = "Cash"
cashFrame.BackgroundTransparency = 1
cashFrame.AnchorPoint = Vector2.new(0, 1)
cashFrame.Position = UDim2.new(0, 16, 1, -14)
cashFrame.Size = UDim2.fromOffset(200, 60)
cashFrame.Parent = gui

local cashScale = Instance.new("UIScale")
cashScale.Parent = cashFrame
bindScale(cashScale)

local cashIcon = Instance.new("ImageLabel")
cashIcon.BackgroundTransparency = 1
-- ============ АЙДИ ИКОНКИ ДЕНЕГ — ВСТАВЛЯЙ СЮДА ============
cashIcon.Image = toImage("ВСТАВЬ_ID_VALUE")
-- ===========================================================
cashIcon.ScaleType = Enum.ScaleType.Fit
cashIcon.Size = UDim2.fromOffset(60, 60)
cashIcon.Parent = cashFrame

local cashLabel = Instance.new("TextLabel")
cashLabel.BackgroundTransparency = 1
cashLabel.Position = UDim2.fromOffset(68, 0)
cashLabel.Size = UDim2.new(1, -68, 1, 0)
cashLabel.Font = Enum.Font.GothamBold
cashLabel.TextSize = 44
cashLabel.TextXAlignment = Enum.TextXAlignment.Left
cashLabel.TextColor3 = Color3.fromRGB(70, 210, 70)
cashLabel.Text = "0"
cashLabel.Parent = cashFrame

local cashStroke = Instance.new("UIStroke")
cashStroke.Thickness = 2
cashStroke.Color = Color3.fromRGB(0, 0, 0)
cashStroke.Parent = cashLabel

local function formatNumber(n)
	local s = tostring(math.floor(n))
	local formatted = s:reverse():gsub("(%d%d%d)", "%1,"):reverse()
	return (formatted:gsub("^,", ""))
end

local function updateCash()
	cashLabel.Text = formatNumber(player:GetAttribute("Cash") or 0)
end
updateCash()
player:GetAttributeChangedSignal("Cash"):Connect(updateCash)