Checkpoints facing the wrong way on spawn/death

Just having a tiny problem in my obby. When you spawn in or die the game turns you the wrong way. I’ve tried rotating the checkpoints and adding spawn points on-top-of and inside the checkpoints themselves but it still didnt work.

Here’s my checkpoint script in serverscriptservice:


local checkpoints = workspace:WaitForChild("Checkpoints")

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local DatastoreService = game:GetService("DataStoreService")
local Data = DatastoreService:GetDataStore("1")
local sessionData = {}

function PlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"

	local stage = Instance.new("NumberValue")
	stage.Name = "Stage"
	stage.Parent = leaderstats

	local success = nil
	local playerData = nil
	local attempt = 1

	repeat 
		success, playerData = pcall(function() -- here pcall or protected call is just repeat waiting until the data loads for the player
			return Data:GetAsync(player.UserId)
		end)

		attempt += 1
		if not success then 
			warn(playerData)
			task.wait(2)
		end

	until success or attempt == 5 -- it repeats it until it loads

	if success then --if it loads then make the table with their data inside
		print("Data loaded: "..player.Name)
		if not playerData then -- if they have no table then they're a new player so we create the table 
			print("new player, giving default data")

			playerData = {
				["Stage"] = 1, --add all your values and stuff inside of the data

			}
		end

		sessionData[player.UserId] = playerData --set the data to a table with the players id and make to make a variable
	else
		warn("couldnt load data: "..player.Name)
		player:Kick("couldnt load your data, rejoin") --if the data couldnt load we kick them so their not just sitting there forever waiting
	end

	stage.Value = sessionData[player.UserId].Stage --here we get the numbervalue created above and get the value of it and set it to the value inside of the table

	stage:GetPropertyChangedSignal("Value"):Connect(function()
		sessionData[player.UserId].Stage = stage.Value --update the table value whenever the leaderstat value changes
	end)


	leaderstats.Parent = player

end

Players.PlayerAdded:Connect(function(player)
	PlayerAdded(player)

	player.CharacterAdded:Connect(function(char)
		local leaderstats = player:WaitForChild("leaderstats")
		local stage = leaderstats.Stage

		local hum = char:WaitForChild("Humanoid")
		task.wait()
		char:MoveTo(checkpoints[stage.Value].Position)

		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				if tonumber(hit.Name) == stage.Value + 1 then
					stage.Value += 1
				end
			end
		end)
	end)
end)



function PlayerLeaving(player)

	if sessionData[player.UserId] then
		local success = nil
		local errorMsg = nil
		local attempt = 1


		repeat
			success, errorMsg = pcall(function()
				Data:SetAsync(player.UserId, sessionData[player.UserId]) --here is the same as loading data just repeat waits until the data saves
			end)

			attempt += 1
			if not success then 
				warn(errorMsg)
				task.wait(2)
			end

		until success or attempt == 5

		if success then 
			print("Data saved: "..player.Name)
		else
			warn("Cant save: "..player.Name)
		end

	end

end

Players.PlayerRemoving:Connect(PlayerLeaving)

function ServerShutdown()
	if RunService:IsStudio() then
		return
	end

	for i, player in ipairs(Players:GetPlayers()) do
		task.spawn(function()
			PlayerLeaving(player)
		end)
	end
end
game:BindToClose(ServerShutdown)

1 Like
Players.PlayerAdded:Connect(function(player)
	PlayerAdded(player)

	player.CharacterAdded:Connect(function(char)
		local leaderstats = player:WaitForChild("leaderstats")
		local stage = leaderstats.Stage

		local hum = char:WaitForChild("Humanoid")
		task.wait()
		--char:MoveTo(checkpoints[stage.Value].Position)
          char.PrimaryPart.CFrame = checkpoints[stage.Value].CFrame * CFrame.new(0,3,0)

		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				if tonumber(hit.Name) == stage.Value + 1 then
					stage.Value += 1
				end
			end
		end)
	end)
end)

try this

1 Like

Now its backwards, do I need to go through and turn all the checkpoints again or something?

no, now just rotate the part that the character gets teleported to 180 degrees and done

1 Like

Got you mane, have a good day. Preciate the help :sunglasses: :100:

1 Like

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