Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local ServerStorage = game:GetService("ServerStorage")
- Players.CharacterAutoLoads = false
- print("Server script started")
- local remote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ChooseCharacter")
- local characterData = require(ReplicatedStorage:WaitForChild("CharacterData"))
- local charactersFolder = ServerStorage:WaitForChild("Characters")
- local function getSpawnCFrame()
- local spawnLocation = workspace:FindFirstChildWhichIsA("SpawnLocation")
- if spawnLocation then
- return spawnLocation.CFrame + Vector3.new(0, 3, 0)
- end
- return CFrame.new(0, 10, 0)
- end
- local function spawnCharacter(player, characterId)
- local template = charactersFolder:FindFirstChild(characterId)
- if not template then
- warn("Не найдена модель персонажа: " .. tostring(characterId))
- return
- end
- local humanoid = template:FindFirstChildOfClass("Humanoid")
- local rootPart = template:FindFirstChild("HumanoidRootPart")
- if not humanoid then
- warn("У персонажа нет Humanoid: " .. characterId)
- return
- end
- if not rootPart then
- warn("У персонажа нет HumanoidRootPart: " .. characterId)
- return
- end
- if player.Character then
- player.Character:Destroy()
- end
- local character = template:Clone()
- character.Name = player.Name
- character.Parent = workspace
- character:PivotTo(getSpawnCFrame())
- player.Character = character
- player:SetAttribute("CharacterChosen", true)
- player:SetAttribute("SelectedCharacter", characterId)
- end
- Players.PlayerAdded:Connect(function(player)
- player:SetAttribute("CharacterChosen", false)
- player:SetAttribute("SelectedCharacter", "")
- end)
- remote.OnServerEvent:Connect(function(player, characterId)
- print("Server received:", player.Name, characterId)
- if player:GetAttribute("CharacterChosen") then
- return
- end
- if typeof(characterId) ~= "string" then
- return
- end
- if not characterData[characterId] then
- warn("Игрок выбрал неизвестного персонажа: " .. characterId)
- return
- end
- player:SetAttribute("CharacterChosen", true)
- spawnCharacter(player, characterId)
- end)
Advertisement
Add Comment
Please, Sign In to add comment