Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local player = Players.LocalPlayer
- local playerGui = player:WaitForChild("PlayerGui")
- local remote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ChooseCharacter")
- local characterData = require(ReplicatedStorage:WaitForChild("CharacterData"))
- local guiTemplate = ReplicatedStorage:WaitForChild("CharacterSelectGui")
- local gui = guiTemplate:Clone()
- gui.Name = "CharacterSelectGui"
- gui.ResetOnSpawn = false
- gui.Enabled = true
- gui.Parent = playerGui
- print("CharacterSelectClient started")
- local mainFrame = gui:WaitForChild("MainFrame")
- local cardsContainer = mainFrame:WaitForChild("Cards")
- local choosing = false
- local function getDescendant(parent, name)
- return parent:FindFirstChild(name, true)
- end
- local function setAllButtonsEnabled(state)
- for _, card in ipairs(cardsContainer:GetChildren()) do
- if card:IsA("Frame") then
- local button = getDescendant(card, "SelectButton")
- if button and button:IsA("TextButton") then
- button.Active = state
- button.AutoButtonColor = state
- if state then
- button.Text = "Выбрать"
- end
- end
- end
- end
- end
- local function setupCard(card)
- if not card:IsA("Frame") then
- return
- end
- local characterId = card:GetAttribute("CharacterId")
- if typeof(characterId) ~= "string" then
- warn("У карточки нет CharacterId: " .. card.Name)
- return
- end
- local data = characterData[characterId]
- if not data then
- warn("Нет данных в CharacterData для: " .. characterId)
- return
- end
- local imageLabel = getDescendant(card, "ImageLabel")
- local nameLabel = getDescendant(card, "NameLabel")
- local descriptionLabel = getDescendant(card, "DescriptionLabel")
- local selectButton = getDescendant(card, "SelectButton")
- if imageLabel and imageLabel:IsA("ImageLabel") then
- imageLabel.Image = data.Image
- end
- if nameLabel and nameLabel:IsA("TextLabel") then
- nameLabel.Text = data.DisplayName
- end
- if descriptionLabel and descriptionLabel:IsA("TextLabel") then
- descriptionLabel.Text = data.Description
- end
- if selectButton and selectButton:IsA("TextButton") then
- selectButton.Text = "Выбрать"
- selectButton.Activated:Connect(function()
- if choosing then
- return
- end
- choosing = true
- setAllButtonsEnabled(false)
- selectButton.Text = "Загрузка..."
- remote:FireServer(characterId)
- end)
- end
- end
- for _, card in ipairs(cardsContainer:GetChildren()) do
- setupCard(card)
- end
- cardsContainer.ChildAdded:Connect(function(child)
- task.wait()
- setupCard(child)
- end)
- remote.OnClientEvent:Connect(function(success, message)
- if success then
- gui.Enabled = false
- else
- choosing = false
- warn(message or "Не удалось выбрать персонажа")
- setAllButtonsEnabled(true)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment