When Respawning, Player is laying down

Hi i am trying to make a checkpoint code so when a player respawns, they spawn on their previous checkpoint but whenever they spawn in, my character falls over and i dont know why?

local players = game:GetService("Players")
local datastoreservice = game:GetService("DataStoreService")
local saveDataStore = datastoreservice:GetDataStore("SaveDataTest")


local function SavePlrData(plr)
	
	local success,err = pcall(function()
		
	
	
	local saveData = {}
	
	for _,stat in pairs(plr.leaderstats:GetChildren()) do
			saveData[stat.Name] = stat.Value
			
		end
		
		saveDataStore:SetAsync(plr.UserId,saveData)
		
	end)
	
	if not success then return err end
	
end
players.PlayerAdded:Connect(function(plr)
	
	local stats = Instance.new("Folder")
	
	stats.Name = "leaderstats"
	stats.Parent = plr
	
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Parent = stats
	
	local data = saveDataStore:GetAsync(plr.UserId)
	
	if data then
		
		
		print(data.Stage)
		
		
		for _,stat in pairs(stats:GetChildren()) do
			stat.Value = data[stat.Name]
		end
		
	else
		print(plr.Name.. "has no data")
	end
	
	
	
	plr.CharacterAdded:Connect(function(char)
		local humanoid,hrp = char:WaitForChild("Humanoid"), char:WaitForChild("HumanoidRootPart")
		
		wait()
		
		if humanoid and hrp then
			if stage.Value ~= 0 then
				local part = workspace.Checkpoints:FindFirstChild(stage.Value)
				hrp.CFrame = part.CFrame + Vector3.new(0,10,0)
			end
		end
	end)
	
end)


players.PlayerRemoving:Connect(function(plr)
	
	local err = SavePlrData(plr)
	
	if err then print(err) end
	
	
end)


game:BindToClose(function()
	
	for _,plr in pairs(players:GetPlayers()) do	local err = SavePlrData(plr)

		if err then print(err) end
		end
	
	wait(2)
	
end)

Heres the script for the checkpoint.

I feel its something to do with the Vector3 but i dont know how to sort this issue

I see what you are trying to script here, but usually stuff like this needs some kinda image or 5 second clip of whats happening to the character. If you can and upload one, We can probably go from there.

robloxapp-20220909-1517153.wmv (1.4 MB)

My only assumption is that maybe how the faces are set up on the checkpoints is somewhat messed up?

Try setting the position rather than the CFrame

hrp.Position = part.Position + Vector3.new(0, 10, 0)
1 Like

when using that my camera spawned where it should but my player spawned at the first stage

Try lowering the amount you offset by, maybe to something like 5 rather than 10? I’ve never seen this happen before

you can add Humanoid:ChangeState(2) after

https://developer.roblox.com/en-us/api-reference/function/Humanoid/ChangeState

i changed it so it has no position at all and now it works haha thankyou!

I would just recommend using PivotTo() on the Character instead of setting the HumanoidRootPart CFrame (This has the advantage of moving the Player even when the HumanoidRootPart doesn’t exist).

char:PivotTo(part.CFrame + CFrame.new(0,10,0))
1 Like

Im also experiencing this same issue, I’ve taken all of the recommended tips on this forum but nothing seems to work. Could this be caused by another script?