Hasli4

Untitled

Aug 5th, 2026
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3.  
  4. local player = Players.LocalPlayer
  5. local playerGui = player:WaitForChild("PlayerGui")
  6.  
  7. local remote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ChooseCharacter")
  8. local characterData = require(ReplicatedStorage:WaitForChild("CharacterData"))
  9.  
  10. local guiTemplate = ReplicatedStorage:WaitForChild("CharacterSelectGui")
  11. local gui = guiTemplate:Clone()
  12. gui.Name = "CharacterSelectGui"
  13. gui.ResetOnSpawn = false
  14. gui.Enabled = true
  15. gui.Parent = playerGui
  16.  
  17. print("CharacterSelectClient started")
  18.  
  19. local mainFrame = gui:WaitForChild("MainFrame")
  20. local cardsContainer = mainFrame:WaitForChild("Cards")
  21.  
  22. local choosing = false
  23.  
  24. local function getDescendant(parent, name)
  25. return parent:FindFirstChild(name, true)
  26. end
  27.  
  28. local function setAllButtonsEnabled(state)
  29. for _, card in ipairs(cardsContainer:GetChildren()) do
  30. if card:IsA("Frame") then
  31. local button = getDescendant(card, "SelectButton")
  32. if button and button:IsA("TextButton") then
  33. button.Active = state
  34. button.AutoButtonColor = state
  35. if state then
  36. button.Text = "Выбрать"
  37. end
  38. end
  39. end
  40. end
  41. end
  42.  
  43. local function setupCard(card)
  44. if not card:IsA("Frame") then
  45. return
  46. end
  47.  
  48. local characterId = card:GetAttribute("CharacterId")
  49. if typeof(characterId) ~= "string" then
  50. warn("У карточки нет CharacterId: " .. card.Name)
  51. return
  52. end
  53.  
  54. local data = characterData[characterId]
  55. if not data then
  56. warn("Нет данных в CharacterData для: " .. characterId)
  57. return
  58. end
  59.  
  60. local imageLabel = getDescendant(card, "ImageLabel")
  61. local nameLabel = getDescendant(card, "NameLabel")
  62. local descriptionLabel = getDescendant(card, "DescriptionLabel")
  63. local selectButton = getDescendant(card, "SelectButton")
  64.  
  65. if imageLabel and imageLabel:IsA("ImageLabel") then
  66. imageLabel.Image = data.Image
  67. end
  68.  
  69. if nameLabel and nameLabel:IsA("TextLabel") then
  70. nameLabel.Text = data.DisplayName
  71. end
  72.  
  73. if descriptionLabel and descriptionLabel:IsA("TextLabel") then
  74. descriptionLabel.Text = data.Description
  75. end
  76.  
  77. if selectButton and selectButton:IsA("TextButton") then
  78. selectButton.Text = "Выбрать"
  79.  
  80. selectButton.Activated:Connect(function()
  81. if choosing then
  82. return
  83. end
  84.  
  85. choosing = true
  86. setAllButtonsEnabled(false)
  87. selectButton.Text = "Загрузка..."
  88. remote:FireServer(characterId)
  89. end)
  90. end
  91. end
  92.  
  93. for _, card in ipairs(cardsContainer:GetChildren()) do
  94. setupCard(card)
  95. end
  96.  
  97. cardsContainer.ChildAdded:Connect(function(child)
  98. task.wait()
  99. setupCard(child)
  100. end)
  101.  
  102. remote.OnClientEvent:Connect(function(success, message)
  103. if success then
  104. gui.Enabled = false
  105. else
  106. choosing = false
  107. warn(message or "Не удалось выбрать персонажа")
  108. setAllButtonsEnabled(true)
  109. end
  110. end)
Advertisement
Add Comment
Please, Sign In to add comment