So I’m trying to make a checkpoint system, sort of like that of an obby game, but it doesn’t seem to be working. I read tutorials and read the roblox documentation on checkpoints, yet I still can’t figure it out. This is a crucial part of my game I’ve been working on, so I appreciate any help.
By the way, my checkpoint value does update after each checkpoint I touch and it saves. The issue is: when I rejoin the game I don’t actually spawn at a checkpoint. I read this could have something to do with having a default roblox spawn point? I did try briefly removing the spawn point, still no luck though
Here’s my checkpoint handler script:
local checkpoints = game.Workspace.Checkpoints:GetChildren()
function gotoCheckpoint(character, checkpoint)
local rootPart = character:WaitForChild("HumanoidRootPart")
repeat wait(0.00) until rootPart
for i, checkpoint in pairs(checkpoints) do
print("Checkpoint".. tostring(checkpoint))
if ("Checkpoint" ..tostring(checkpoint)) == checkpoint.Name then
print("Check- poiiiiiiints fouwwwwwwwwnd")
rootPart.CFrame = checkpoint.CFrame * CFrame.new(0,1,0)
break
end
end
end
game:GetService("Players").PlayerAdded:Connect(function(player)
local CheckPoint = player:WaitForChild("Checkpoint")
player.CharacterAdded:Connect(function(character)
wait(0.01)
gotoCheckpoint(character, CheckPoint.Value)
end)
end)
for i, checkpoint in pairs(checkpoints) do
checkpoint.Touched:Connect(function(touch)
local hum = touch.Parent:FindFirstChild("Humanoid")
if hum and hum.Health > 0 then
local player = game:GetService("Players"):GetPlayerFromCharacter(touch.Parent)
local CheckPoint = player.Checkpoint
if player then
if (tonumber(checkpoint.Name:match("%d+"))-CheckPoint.Value) == 1 then
CheckPoint.Value += 1
end
end
end
end)
end
My datastore script is a different script, also worth knowing that i have a checkpoints folder in the workspace with 2 checkpoints “2” and “3” because the checkpoints value is 1 by default
Are there any logs in the ‘Output’, such as errors being unable to fetch players being added and moving their character to a specified location? If so please provide a screenshot.
If so, please could you alternatively provide your Datastore Manager script and the full script that is managing the checkpoints. I don’t seem to see how your datastore manager is fetching user data, such as their current checkpoint.
Seems like it’s an issue with fetching player data, if you could provide your datastore script that manages fetching player data I could better understand the issue.
local DSS = game:GetService("DataStoreService")
local MyStore = DSS:GetDataStore("GOAWv1")
game.Players.PlayerAdded:Connect(function(player)
wait()
local playerKey = "id_"..player.UserId
local saveValue1 = player.Coins
local saveValue2 = player.Checkpoint
local GetSaved = MyStore:GetAsync(playerKey)
if GetSaved then
saveValue1.Value = GetSaved[1]
saveValue2.Value = GetSaved[2]
else
local valuestosave = {saveValue1.Value, saveValue2.Value}
MyStore:GetAsync(playerKey, valuestosave)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local saveItems = {player.Coins.Value, player.Checkpoint.Value}
MyStore:SetAsync("id_"..player.UserId, saveItems)
end)
game:BindToClose(function()
for i, plr in pairs(game.Players:GetChildren()) do
plr:Kick("All data has been saved! Yippe!")
end
end)
leaderstats is also its own script, all values are saved in the player, not leaderstats though
make a folder for every checkpoint and name every checkpint 1,2,3,4,5 etc
when the player touchs a checkpoint check if the ( checkpoint name == (player.level + 1) ) if so then make the player level = the checkpoint name / player.level = toNumber(checkpoint.Name)
check for Player.Character.CharacterAdded:Connect() and teleport the player to the checkpoint smt like this
local Checkpoints = workspace.CheckPointsFolder
CharacterAdded:Connect(function(character)
local level = player.leaderstats.level
character.HumanoidRootPart.Position = Checkpoints[level.Value].Position
)
i wrote this in the forum itself so it may have some errors
Okay, so i was able to re-order the checkpoints so that the player now spawns at checkpoint one, but when i go to checkpoint 2 it updates the stats still, but doesn’t put me back there after i rejoin
i made a script and tested and it worked disable your script and add this and see if it will work
local Players = game:GetService("Players")
local CheckPoints = workspace.CheckPoints
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder") ; leaderstats.Name = "leaderstats" ; leaderstats.Parent = player
local level = Instance.new("IntValue") ; level.Name = "level" ; level.Parent = leaderstats
player.CharacterAdded:Connect(function(character)
character:PivotTo(CheckPoints[level.Value].CFrame) -- spawn player at the checkpoint
end)
end)
for _,CheckPoint :Part in CheckPoints:GetChildren() do
CheckPoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = Players:GetPlayerFromCharacter(hit.Parent) -- get player
Player.leaderstats.level.Value = CheckPoint.Name -- change the player level value
end
end)
end
amnot good at data stores but you can set the player data first before spawning him
yeah, im sorry but the same thing keeps happening! the leaderstats will update seamlessly and it saves, cause i already have a datastore in place, but it just doesnt want to teleport the player to their current checkpoint
You should wrap your DataStore access with pcall() and check the return values. There are a few nuances in the meaning of the return values.
local success, data = pcall(function()
return MyStore:GetAsync(playerKey);
end)
if success is false then access to the DataStore was unsuccessful, this could be due to any number of reasons: Roblox servers could be down, or this single call failed for whatever reason. Not checking for a failed DataStore access can result in a player being assigned new data, wiping out their current data if they already have one (MEGA data loss!!). If success is true and data is nil then no data exists for that player, and so a new store needs to be created. If success is true and data is not nil then the players data exists and is read-writable.