Obby checkpoint script

I’m trying to make an obby game, and I’m watching a tutorial on how to make a " Saving Obby Checkpoints", but when I test it out, in the “Output” section it says " Checkpoints is not a valid member of Workspace “Workspace” - Server - CheckpointScript:7" I have tried taking away ) but it still does not work.

Code:

local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore("PlayerStageDataStore")

function plrToStage(plr)
	repeat wait() until plr.Character.HumanoidRootPart
	
	local stagePart = game.Workspace.Checkpoints:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
	
	plr.Character.HumanoidRootPart.CFrame = stagePart.CFrame + Vector3.new(0,2.5,0)
end

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Parent = leaderstats
	
	local success, errorMsg = pcall(function()
		stage.Value = stageStore:GetAsync(player.UserId)
	end)
	
	if success then
		print("Successfully got "..player.Name.."'s stage data.")
	else
		warn(errorMsg)
	end
	
	if player.Character then
		plrToStage(player)
	end
	
	player.CharacterAdded:Connect(function()
		plrToStage(player)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errorMsg = pcall(function()
		stageStore:SetAsync(player.UserId,player.leaderstats.Stage.Value)
	end)
	
	if success then
		print("Successfully got "..player.Name.."'s stage data.")
	else
		warn(errorMsg)
	end	
end)

for _, cheackpoint in pairs(game.Workspace.Checkpoints:GetChildren()) do
	cheackpoint.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			local cheackpointNumber = tonumber(cheackpoint.Name)
			
			if player.leaderstats.Stage.Value < cheackpointNumber then
				player.leaderstats.Stage.Value = cheackpointNumber
			end
		end
	end)
end

When he is scripting the part:

Plz tell me what I need to add or remove, because I don’t see where I went wrong.

1 Like

Is there a folder located in Workspace named Checkpoints? That might be your problem.

1 Like

Yes, I have a folder named Checkpoints

Try calling workspace instead of game.Workspace and also use :WaitForChild.
Like this:

local stagePart = workspace:WaitForChild("Checkpoints"):FindFirstChild(tostring(plr.leaderstats.Stage.Value))
1 Like

I tried it, but it did not work

So, I just made sure I spelt Checkpoints right, and on the folder I did not, so I changed it and now it works, I fill so stupid right now, also thx for trying to help me and sorry for wasting your time

Now it’s not saving my data, so when I leave the game it takes me back to stage 0

Does the console output anything, and also are the checkpoint objects named numerically?

502: API Services rejected request with error. Error code: 7 Reason: Studio access to APIs is not allowed. - Server - CheckpointScript:28

Yes

That’s the problem, the API services for Roblox Studio are not allowed. To activate them go into the game settings and then go to permissions and enable API Acess.

3 Likes

It worked, thank you for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.