First of all im gonna explain my game, my game is a obby game but you are chasing by npc if npc catchs you, you lose your all Checkpoints. The problem is i dont know how to reset checkpoints, here is my codes:
local Checkpoints = script.Parent
for i,v in pairs(Checkpoints:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player.leaderstats.Checkpoint.Value < tonumber(v.Name) then
player.leaderstats.Checkpoint.Value = tonumber(v.Name)
end
end
end
end)
end
end
.
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"
local Checkpoint = Instance.new("IntValue", leaderstats)
Checkpoint.Name = "Checkpoint"
Checkpoint.Value = 1
Player.CharacterAdded:Connect(function(Character)
repeat wait() until Player.Character ~= nil
local checkpoint = game.Workspace.Checkpoints:FindFirstChild(Checkpoint.Value)
Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position + Vector3.new(0,2,0))
end)
end)
I tried to reset like this but it didnt work,
wait()
local dum = game.Workspace.CellatBaba
local players = game:GetService("Players")
local lead = game.Players:WaitForChild("leaderstats", 1)
game.Workspace.CellatBaba.Hitbox.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
game.Workspace.CellatBaba:SetPrimaryPartCFrame(CFrame.new(0,0,0))
hit.Parent.Humanoid.Health = 0
Player.leaderstats.Checkpoint.Value = 0
end
end)
Player.leaderstats.Checkpoint.Value = 0
i thought doing that i can reset checkpoints but i cannot, what should i do ?

1 comment
if you are using teams for the checkpoint then just set the players team to the first checkpoint