я могу много раз вызывать ошибку и она будет скапливатся в одном месте также многие…
- User
я могу много раз вызывать ошибку и она будет скапливатся в одном месте также многие просто исчезали когда прошло 3 секунды также ошибка не плавно "вызежает" local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui") local ProductData = require(ReplicatedStorage:WaitForChild("Products")) local TemplateFrame = script.Parent.ScrollingFrame.Template local PurchaseProduct = ReplicatedStorage.Remotes:WaitForChild("PurchaseProduct") local ErrorTextTemplate = script.Parent.Parent.Error.TextLabel -- Шаблон для ошибок local errorCount = 0 -- Счетчик ошибок
-- Функция для отображения ошибки local function showError(message) if errorCount < 2 then -- Максимум 2 ошибки errorCount = errorCount + 1
-- Создаем дубликат ErrorText local newErrorText = ErrorTextTemplate:Clone() newErrorText.Text = message newErrorText.Visible = true -- Расположение нового сообщения об ошибке newErrorText.Position = UDim2.new(0, 0, 0, -50 * (errorCount - 1)) -- Смещение вниз newErrorText.Parent = script.Parent.Parent.Error -- Устанавливаем родителем PlayerGui -- Анимация "выезда" local goal = {Position = UDim2.new(0, 0, 0, 0)} -- Позиция "въезда" local tweenInfo = TweenInfo.new(0.5) -- Время анимации local tween = game:GetService("TweenService"):Create(newErrorText, tweenInfo, goal) tween:Play() -- Ждем 3 секунды и затем "въедем" обратно wait(3) -- Анимация "въезда" обратно local goalBack = {Position = UDim2.new(0, 0, -0.5, 0)} -- Позиция "въезда" обратно local tweenBack = game:GetService("TweenService"):Create(newErrorText, tweenInfo, goalBack) tweenBack:Play() tweenBack.Completed:Wait() -- Ждем окончания анимации newErrorText:Destroy() -- Удаляем текст ошибки после анимации errorCount = errorCount - 1 -- Уменьшаем счетчик endend
-- Функция для создания Frame с деталями продукта local function CreateProductFrame(productIndex, product) local newFrame = TemplateFrame:Clone() newFrame.Visible = true newFrame.Name = product.Name
newFrame:FindFirstChild("Product").Text = product.Name newFrame:FindFirstChild("Cost").Text = "Cost: " .. product.Price .. "$ For unit" local quantityBox = newFrame:FindFirstChild("Quantity") local totalCostLabel = newFrame:FindFirstChild("TotalCost") local buyButton = newFrame:FindFirstChild("Buy") -- Функция для обновления общей стоимости local function updateTotalCost() local quantity = tonumber(quantityBox.Text) or 0 local totalCost = product.Price * quantity totalCostLabel.Text = "Total: " .. totalCost .. "$" end -- Обработка потери фокуса в поле ввода количества quantityBox.FocusLost:Connect(function(enterPressed) if enterPressed or not quantityBox:IsFocused() then local quantity = tonumber(quantityBox.Text) if quantity and quantity > 0 then quantity = math.floor(quantity) if quantity > 0 and quantity <= 100000 then quantityBox.Text = tostring(quantity) updateTotalCost() else print("Invalid quantity entered. Please enter a whole number between 1 and 100000.") showError("Invalid quantity entered.") quantityBox.Text = "0" end else quantityBox.Text = "0" end end end) -- Обработка нажатия на кнопку покупки buyButton.MouseButton1Click:Connect(function() local quantity = tonumber(quantityBox.Text) if quantity and quantity > 0 and quantity <= 100000 then print("Player wants to buy " .. quantity .. " units of " .. product.Name) PurchaseProduct:FireServer(productIndex, quantity) -- Отправляем индекс продукта и количество на сервер else print("Invalid quantity entered.") showError("Invalid quantity entered.") end end) newFrame.Parent = TemplateFrame.Parent - Assistant