Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My checkpoint system isn't working Any help? Throwing no error.

Hi there. I am working an an obby game, and yet again have stumbled upon a problem. Everything with the checkpoint system is working except for teleporting to a checkpoint when the player joins (Saved within DataStore). Can somebody please help? My code is here:

game.Players.PlayerAdded:Connect(function(plr)
	local waitforleaderstats = plr:WaitForChild('leaderstats')
	if waitforleaderstats ~= nil then
		local ls = plr.leaderstats
		local rl = plr.RespawnLocation
		local cp = game.Workspace.Checkpoints
		
		if ls.Stage.Value == 0 then
			rl = cp.Checkpoint1

		elseif ls.Stage.Value == 1 then
			rl = cp.Checkpoint1

		elseif ls.Stage.Value == 2 then
			rl = cp.Effortless.Checkpoint2

		elseif ls.Stage.Value == 3 then
			rl = cp.Effortless.Checkpoint3

		elseif ls.Stage.Value == 4 then
			rl = cp.Effortless.Checkpoint4

		elseif ls.Stage.Value == 5 then
			rl = cp.Effortless.Checkpoint5

		elseif ls.Stage.Value == 6 then
			rl = cp.Effortless.Checkpoint6

		elseif ls.Stage.Value == 7 then
			rl = cp.Effortless.Checkpoint7

		elseif ls.Stage.Value == 8 then
			rl = cp.Effortless.Checkpoint8

		elseif ls.Stage.Value == 9 then
			rl = cp.Effortless.Checkpoint9

		elseif ls.Stage.Value == 10 then
			rl = cp.Easy.Checkpoint10

		elseif ls.Stage.Value == 11 then
			rl = cp.Easy.Checkpoint11

		elseif ls.Stage.Value == 12 then
			rl = cp.Easy.Checkpoint12

		elseif ls.Stage.Value == 13 then
			rl = cp.Easy.Checkpoint13

		elseif ls.Stage.Value == 14 then
			rl = cp.Easy.Checkpoint14

		elseif ls.Stage.Value == 15 then
			rl = cp.Easy.Checkpoint14
		end
	end
end)

Sorry that it's long, couldn't think of any other way to do it.

2 comments

0

where's the teleport script ?

0

did you set a gui?

1 answer

Make sure you create a leaderstats intvalue called "Checkpoint", and create a folder for your spawns named "Spawns". Put all of the checkpoint parts in the "Spawns" folder, AND MAKE SURE THAT YOU NAME THE CHECKPOINT PART'S NAME TO A NUMBER THAT YOU WANT TO CHANGE YOUR CHECKPOINT TO. (Ex. 1st checkpoint's name: "1", 2nd checkpoint's name: "2").

Lemme simplify your code for you. Also the reason why the character isn't teleporting is because the code only runs when the players joins the game. Here's the code:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local CheckPoint = player:WaitForChild('leaderstats'):WaitForChild('Checkpoint')
		local SpawnPoints = workspace:WaitForChild('Spawns')

		local humanoid = character:WaitForChild('Humanoid')

		humanoid.Touched:Connect(function(touch)
			if touch.Parent = SpawnPoints then -- The object touched is a checkpoint.
				if CheckPoint.Value == tonumber(touch.Name) + 1 then
					CheckPoint.Value += 1
				end
			end
		end)

		repeat wait() until character:FindFirstChild('HumanoidRootPart')
		local rootPart = humanoid.RootPart
		rootPart.CFrame = CFrame.new(SpawnPoints:GetChildren()[CheckPoint.Value].Position) + Vector3.new(0, 2, 0)
	end)
end)

1 comment

0

No. That inteferes with my other scripts.

This discussion is preserved as it was. New answers, comments, and votes are closed.