Hasli4

Untitled

Jul 26th, 2026
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local ServerStorage = game:GetService("ServerStorage")
  4.  
  5. Players.CharacterAutoLoads = false
  6.  
  7. print("Server script started")
  8.  
  9. local remote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ChooseCharacter")
  10. local characterData = require(ReplicatedStorage:WaitForChild("CharacterData"))
  11. local charactersFolder = ServerStorage:WaitForChild("Characters")
  12.  
  13. local function getSpawnCFrame()
  14. local spawnLocation = workspace:FindFirstChildWhichIsA("SpawnLocation")
  15. if spawnLocation then
  16. return spawnLocation.CFrame + Vector3.new(0, 3, 0)
  17. end
  18. return CFrame.new(0, 10, 0)
  19. end
  20.  
  21. local function spawnCharacter(player, characterId)
  22. local template = charactersFolder:FindFirstChild(characterId)
  23. if not template then
  24. warn("Не найдена модель персонажа: " .. tostring(characterId))
  25. return
  26. end
  27.  
  28. local humanoid = template:FindFirstChildOfClass("Humanoid")
  29. local rootPart = template:FindFirstChild("HumanoidRootPart")
  30.  
  31. if not humanoid then
  32. warn("У персонажа нет Humanoid: " .. characterId)
  33. return
  34. end
  35.  
  36. if not rootPart then
  37. warn("У персонажа нет HumanoidRootPart: " .. characterId)
  38. return
  39. end
  40.  
  41. if player.Character then
  42. player.Character:Destroy()
  43. end
  44.  
  45. local character = template:Clone()
  46. character.Name = player.Name
  47. character.Parent = workspace
  48. character:PivotTo(getSpawnCFrame())
  49.  
  50. player.Character = character
  51. player:SetAttribute("CharacterChosen", true)
  52. player:SetAttribute("SelectedCharacter", characterId)
  53. end
  54.  
  55. Players.PlayerAdded:Connect(function(player)
  56. player:SetAttribute("CharacterChosen", false)
  57. player:SetAttribute("SelectedCharacter", "")
  58. end)
  59.  
  60. remote.OnServerEvent:Connect(function(player, characterId)
  61. print("Server received:", player.Name, characterId)
  62.  
  63. if player:GetAttribute("CharacterChosen") then
  64. return
  65. end
  66.  
  67. if typeof(characterId) ~= "string" then
  68. return
  69. end
  70.  
  71. if not characterData[characterId] then
  72. warn("Игрок выбрал неизвестного персонажа: " .. characterId)
  73. return
  74. end
  75.  
  76. player:SetAttribute("CharacterChosen", true)
  77. spawnCharacter(player, characterId)
  78. end)
Advertisement
Add Comment
Please, Sign In to add comment