I’m trying to add a win system to my obby game, I have the leaderboard working but I am having trouble with the scripting. My problem is that the game keeps awarding the player wins over and over if the condition is met. How can I make it only award the player once?
local function setupCheckpoints()
for stage = 1, #checkpoints do
local checkpoint = checkpoints[stage]
checkpoint.Touched:Connect(function(hit)
local player = getPlayerFromPart(hit)
if player then
if delays[player] then return end
delays[player] = true
local playerStage = player.Data.Stage.Value
local character = player.Character
local humanoid = character.Humanoid
local isAlive = humanoid:GetState() ~= Enum.HumanoidStateType.Dead
if isAlive then
if stage > playerStage then
player.Data.Stage.Value = stage
end
end
if playerStage > 51 then
player.Data.Stage.Value = 51
warn("Checkpoint Error: Overflow")
end
if playerStage == 51 then
player.Data.Wins.Value += 1
print("Checkpoint Notification: Win Added")
end
task.wait(1)
delays[player] = nil
end
end)
end
end