-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckpoint.lua
More file actions
28 lines (25 loc) · 994 Bytes
/
Copy pathCheckpoint.lua
File metadata and controls
28 lines (25 loc) · 994 Bytes
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
-- give every checkpoint a unique value
-- this value represents progress, so every checkpoint you reach should have a higher value than the last
local CHECKPOINT_VALUE = 1
local Players = game:GetService("Players")
local checkpointArea = script.Parent
checkpointArea.Anchored = true
checkpointArea.CanCollide = true
local COOLDOWN_TIME = 5
local function onPartTouch(otherPart)
local partParent = otherPart.Parent
local player = Players:GetPlayerFromCharacter(partParent)
local leaderstats = player and player:FindFirstChild("leaderstats")
local progressStat = leaderstats and leaderstats:FindFirstChild("Checkpoint")
if progressStat then
if not checkpointArea:GetAttribute("CoolingDown") then
checkpointArea:SetAttribute("CoolingDown", true)
if CHECKPOINT_VALUE > progressStat.Value then
progressStat.Value = CHECKPOINT_VALUE
end
task.wait(COOLDOWN_TIME)
checkpointArea:SetAttribute("CoolingDown", false)
end
end
end
checkpointArea.Touched:Connect(onPartTouch)