Player character offset upwards when dead

I am trying to make a checkpoint system using CollectionService. But when I reset, I spawn at the checkpoint but the character’s position is offset upwards.

Script:

local CollectService = game:GetService("CollectionService")

local checkpoints = CollectService:GetTagged("Checkpoint")

local Players = game.Players

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local checkpoint = Instance.new("NumberValue")
	checkpoint.Name = "Checkpoint"
	checkpoint.Parent = leaderstats
	
	player.CharacterAdded:Wait()
	player.Character:WaitForChild("Humanoid").Died:Connect(function()
		player.CharacterAdded:Wait()
		
		local root = player.Character:WaitForChild("HumanoidRootPart")
		
		for _, v in ipairs(checkpoints) do
			if v:IsA("BasePart") then
				if v.Name == "Checkpoint"..checkpoint.Value then
					root.Position = v.Position
				end
			end
		end
	end)
end)

for _, v in ipairs(checkpoints) do
	if v:IsA("BasePart") and v:FindFirstChild("Checkpoint") then
		v.Touched:Connect(function(hit)
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			if player then
				player:WaitForChild("leaderstats"):WaitForChild("Checkpoint").Value = v.Checkpoint.Value
			end
		end)
	end
end

FOOTAGE:
robloxapp-20240227-0929107.wmv (2.2 MB)

Never mind, the issue is solved. I just had to swap the Position property with the CFrame property.

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