Why isn't my checkpoint script working?

It’s a local script and it’s in startercharacter. I am not getting any errors. It’s teleporting me to the first spawn even if I touched the other spawns

local hum = script.Parent:WaitForChild("Humanoid")

local char = script.Parent
local player = game.Players:FindFirstChild(char.name)
Level= player.leaderstats.Level

char.PrimaryPart = char.HumanoidRootPart


Level= player.leaderstats.Level

local Health = hum.Health

if Health <= 0 then
	repeat wait() until Health == 100
	if Level== 1 then
		char.HumanoidRootPart.Position = game.Workspace.LevelOne.Position
	elseif Level== 2 then
		char.HumanoidRootPart.Position = game.Workspace.LevelTwo.Position
	elseif Level== 3 then
		char.HumanoidRootPart.Position = game.Workspace.LevelThree.Position
	elseif Level== 4 then
		char.HumanoidRootPart.Position = game.Workspace.LevelFour.Position
	elseif Level== 5 then
		char.HumanoidRootPart.Position = game.Workspace.LevelFive.Position
	elseif Level== 6 then
		char.HumanoidRootPart.Position = game.Workspace.LevelSix.Position
	end
end

You want to use char:SetPrimaryPartCFrame() instead of char.HumanoidRootPart.Position.

What’s happening currently is only HumanoidRootPart is moving to the level position.

local hum = script.Parent:WaitForChild("Humanoid")

local char = script.Parent
local player = game.Players:FindFirstChild(char.name)
Level= player.leaderstats.Level

char.PrimaryPart = char.HumanoidRootPart

Level= player.leaderstats.Level

local Health = hum.Health
if Health <= 0 then
	repeat wait() until Health == 100
	if Level== 1 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelOne.CFrame)
	elseif Level== 2 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelTwo.CFrame)
	elseif Level== 3 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelThree.CFrame)
	elseif Level== 4 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelFour.CFrame)
	elseif Level== 5 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelFive.CFrame)
	elseif Level== 6 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelSix.CFrame)
	end
end
1 Like

“Not working” is unhelpful. What doesn’t work?
What should your Script do? What error messages are appearing?

Also, if @Lord_Superbithia solved your issue, mark his post as “solution”

You should use the string library (string | Documentation - Roblox Creator Hub) or just name your checkpoints as integers to check where to put the character when they hit a checkpoint. Using if-statements like this is messy and is a pain to look at/edit.

And I think your problem is that you are comparing a number to an instance and/or you aren’t incrementing player.leaderstats.Level

local hum = script.Parent:FindFirstChild("Humanoid")

local char = script.Parent

local player = game.Players:FindFirstChild(char.name)

char.PrimaryPart = char.HumanoidRootPart

Level= player.leaderstats.Seviye


health = hum.Health


function died()
	print("aaaaaaa")
	if Level.Value == 1 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelOne.CFrame)
	elseif Level.Value == 2 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelTwo.CFrame)
	elseif Level.Value == 3 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelThree.CFrame)
	elseif Level.Value == 4 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelFour.CFrame)
	elseif Level.Value == 5 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelFive.CFrame)
	elseif Level.Value == 6 then
		char:SetPrimaryPartCFrame(game.Workspace.LevelSix.CFrame)
	else
		char:SetPrimaryPartCFrame(game.Workspace.SpawnLocation.CFrame)
	end
end

died()