-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkpoint
28 lines (25 loc) · 1 KB
/
checkpoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--spawn on this object when you touch it.
local spawn = script.Parent
spawn.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
if not checkpointData then
checkpointData = Instance.new("Model", game.ServerStorage)
checkpointData.Name = "CheckpointData"
end
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()
local newUser = tostring(player.userId)
local newData = game.ServerStorage.CheckpointData[newUser].Value.CFrame
local newCheckpoint = newData + Vector3.new(0, 4, 0)
character:WaitForChild("HumanoidRootPart").CFrame = newCheckpoint
end)
end
checkpoint.Value = spawn
end
end)