Как создать систему чекпоинтов в Roblox Studio
Скрипт в ServerScriptStorage: local checkpointsFolder = game.Workspace.Checkpoints -- Функция с событием захода игрока в игру: game.Players.PlayerAdded:Connect(function(player) -- Выполнение одинаковых действий для всех чекпоинтов: for i, checkpoint in pairs(checkpointsFolder:GetChildren()) do local used = {} -- Функция с событием прикосновения к чекпоинту: checkpoint.Touched:Connect(function(object) -- если игрок дотронулся до чекпоинта, тогда активируем чекпоинт: if object and object.Parent == player.Character and not used[i] then used[i] = true SetCheckpoint(object, checkpoint) end end) end end) -- Функция для возрождения игрока на чекпоинте: function SetCheckpoint(whoToSave, checkpointPart) -- сохранение модели игрока: local player = game.Players:GetPlayerFromCharacter(whoToSave.Parent) local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData") if not checkpointData then checkpointData = Instance.new("Model", game.ServerStorage) checkpointData.Name = "CheckpointData" end -- сохранение ID номера игрока: local checkpoint = checkpointData:FindFirstChild(tostring(player.userId)) if not checkpoint then checkpoint = Instance.new("ObjectValue", checkpointData) checkpoint.Name = tostring(player.userId) -- возрождение игрока на чекпоинте: player.CharacterAdded:Connect(function(character) wait() character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0) end) end checkpoint.Value = checkpointPart end
Скрипт в ServerScriptStorage: local checkpointsFolder = game.Workspace.Checkpoints -- Функция с событием захода игрока в игру: game.Players.PlayerAdded:Connect(function(player) -- Выполнение одинаковых действий для всех чекпоинтов: for i, checkpoint in pairs(checkpointsFolder:GetChildren()) do local used = {} -- Функция с событием прикосновения к чекпоинту: checkpoint.Touched:Connect(function(object) -- если игрок дотронулся до чекпоинта, тогда активируем чекпоинт: if object and object.Parent == player.Character and not used[i] then used[i] = true SetCheckpoint(object, checkpoint) end end) end end) -- Функция для возрождения игрока на чекпоинте: function SetCheckpoint(whoToSave, checkpointPart) -- сохранение модели игрока: local player = game.Players:GetPlayerFromCharacter(whoToSave.Parent) local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData") if not checkpointData then checkpointData = Instance.new("Model", game.ServerStorage) checkpointData.Name = "CheckpointData" end -- сохранение ID номера игрока: local checkpoint = checkpointData:FindFirstChild(tostring(player.userId)) if not checkpoint then checkpoint = Instance.new("ObjectValue", checkpointData) checkpoint.Name = tostring(player.userId) -- возрождение игрока на чекпоинте: player.CharacterAdded:Connect(function(character) wait() character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0) end) end checkpoint.Value = checkpointPart end



