Untuk membuat checkpoint di Roblox, kita perlu membuat sebuah object, misal balok kotak. Kita centang CanCollide dan Anchored.
Terus tambahkan script ini:
local checkpoint = script.Parent
checkpoint.Touched:Connect(function(hit)
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player and character:FindFirstChild("HumanoidRootPart") then
-- Simpan posisi checkpoint di attribute player
player:SetAttribute("Checkpoint", checkpoint.Position + Vector3.new(0, 5, 0))
print(player.Name .. " reached checkpoint at " .. tostring(checkpoint.Position))
end
end)
Setelah itu, Di ServerScriptService, tambahkan Script baru (misalnya CheckpointHandler) dengan isi:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local checkpointPos = player:GetAttribute("Checkpoint")
if checkpointPos then
-- kalau player sudah punya checkpoint, spawn di sana
local root = character:WaitForChild("HumanoidRootPart")
task.wait(0.1) -- kasih jeda supaya posisi stabil
root.CFrame = CFrame.new(checkpointPos)
else
-- kalau belum punya checkpoint, biarkan spawn default (SpawnLocation)
print(player.Name .. " spawn di lokasi default")
end
end)
end)