I’m making a checkpoint data store thing in a obby game for someone else, although I’m facing an issue where
- I don’t get teleported to the designated checkpoint and
- every time I purchase the skip stage developer product, It doesn’t do anything.
There are no errors, and I’m not sure what’s wrong with it.
local checkpoints = workspace:WaitForChild("Checkpoints")
local DataStore = game:GetService("DataStoreService")
local checkPointData = DataStore:GetDataStore("CheckpointData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local level = Instance.new("IntValue")
level.Name = "level"
local levelNumber = checkPointData:GetAsync(player.UserId)
if levelNumber then
level.Value = levelNumber
else if not levelNumber then
level.Value = 1
end
end
level.Parent = leaderstats
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char.PrimaryPart.CFrame = checkpoints[level].Position
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
if tonumber(hit.Name) == level.Value + 1 then
level.Value = level.Value + 1
print(level.Value + 1)
end
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player.leaderstats
local level = leaderstats.level
local success, errorMessage = pcall(function()
checkPointData:SetAsync(player.UserId, level.Value)
end)
if errorMessage then
error("Player ("..player.Name..")'s data couldn't be saved.")
end
end)