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 spawnPoint = workspace:WaitForChild("CharacterSpawnPoint")
- local function spawnCharacter(player, characterId)
- local template = charactersFolder:FindFirstChild(characterId)
- if not template then
- return false, "Не найдена модель персонажа: " .. tostring(characterId)
- end
- local character = template:Clone()
- character.Name = player.Name
- character.Parent = workspace
- local ok, err = pcall(function()
- character:PivotTo(spawnPoint.CFrame + Vector3.new(0, 3, 0))
- end)
- if not ok then
- character:Destroy()
- return false, "Не удалось переместить персонажа: " .. tostring(err)
- end
- player.Character = character
- player:SetAttribute("CharacterChosen", true)
- player:SetAttribute("SelectedCharacter", characterId)
- return true
- end
- Players.PlayerAdded:Connect(function(player)
- player:SetAttribute("CharacterChosen", false)
- player:SetAttribute("SelectedCharacter", "")
- end)
- remote.OnServerEvent:Connect(function(player, characterId)
- if player:GetAttribute("CharacterChosen") then
- return
- end
- if typeof(characterId) ~= "string" then
- remote:FireClient(player, false, "Неверный CharacterId")
- return
- end
- if not characterData[characterId] then
- remote:FireClient(player, false, "Нет данных в CharacterData для " .. characterId)
- return
- end
- local success, errorMessage = spawnCharacter(player, characterId)
- if success then
- remote:FireClient(player, true)
- else
- remote:FireClient(player, false, errorMessage)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment