Obby Spawn Point Not Working

Obby Spawn Point Not Working

What I want to achieve:

An obby checkpoint system/ui where it allows you to skip and load your level when you re-join the game.

The issue:

Whenever you die, you always spawn at the main (first) spawn point rather than each individual checkpoint + you have to click the ‘load stage’ button every time to go back to where you were.

https://gyazo.com/d79e2bff407b0a5164ae83503c2db5e7

Solutions I’ve tried:

I’ve asked the person I commissioned to do this however they said they were unable to fix it. (I am not a scripter.)

The script

I’m not sure which one it is so I’ve included both.

Obby Script
local dataStoreService = game:GetService("DataStoreService")
local saveDataStore = dataStoreService:GetDataStore("SaveData")

local function savePlayerData(player)
	local success,err = pcall(function()
		local saveData = {}
		for _, stat in pairs(player.leaderstats:GetChildren()) do
			saveData[stat.Name] = stat.Value
		end
		saveDataStore:SetAsync(player.UserId,saveData)
	end)
	if not success then return err end
end

players.PlayerAdded:Connect(function(player)
	
	local _stats = Instance.new("Folder")
	_stats.Name = "leaderstats"
	_stats.Parent = player
	
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Parent = _stats
	
	local data = saveDataStore:GetAsync(player.UserId)
	if data then
		print(data.Stage)
		for _, stat in pairs(_stats:GetChildren()) do
			stat.Value = data[stat.Name]
		end
	else
		print(player.Name .. " has no data")
	end
	
	player.CharacterAdded:Connect(function(char)
		local humanoid,hrp = char:WaitForChild("Humanoid"),char:WaitForChild("HumanoidRootPart")
		wait()
		if humanoid and hrp then
			if stage.Value ~= 0 then
				--
			end
		end
	end)
	
end)

players.PlayerRemoving:Connect(function(player)
	local err = savePlayerData(player)
	if err then print(err) end
end)

game:BindToClose(function()
	for _,player in pairs(players:GetPlayers()) do
		local err = savePlayerData(player)
		if err then print(err) end
	end
	wait(2)
end)```
Player Script

for _, stage in pairs(stages:GetChildren()) do
	stage.Touched:Connect(function(hit)
		local hum
		if hit.Parent:FindFirstChild("Humanoid") then
			hum = hit.Parent.Humanoid
		end
		if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
			hum = hit.Parent.Parent.Humanoid
		end
		if hum then
			local player = game.Players:GetPlayerFromCharacter(hum.Parent)
			local playerStage = player.leaderstats.Stage.Value
			if tonumber(stage.Name) == playerStage + 1 then
				player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
			elseif tonumber(stage.Name) > playerStage + 1 then
				hum.Health = 0
			end
		end
	end)
end```

Thanks for reading and if you know how to fix this please let me know! :pray:

2 Likes

Change code inside of CharacterAdded inside Obby Script to this:

local humanoid,hrp = char:WaitForChild("Humanoid"),char:WaitForChild("HumanoidRootPart")
wait()
if humanoid and hrp then
	if stage.Value ~= 0 then
		local part = game.Workspace.ObbyStages:FindFirstChild(stage.Value)
		hrp.CFrame = part.CFrame + Vector3.new(0,1,0)
	end
end
1 Like

If this is what you mean it’s not working for me. Do the checkpoints need to be Spawn Locations, because they are currently just parts?

local dataStoreService = game:GetService("DataStoreService")
local saveDataStore = dataStoreService:GetDataStore("SaveData")

local function savePlayerData(player)
	local success,err = pcall(function()
		local saveData = {}
		for _, stat in pairs(player.leaderstats:GetChildren()) do
			saveData[stat.Name] = stat.Value
		end
		saveDataStore:SetAsync(player.UserId,saveData)
	end)
	if not success then return err end
end

players.PlayerAdded:Connect(function(player)
	
	local _stats = Instance.new("Folder")
	_stats.Name = "leaderstats"
	_stats.Parent = player
	
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Parent = _stats
	
	local data = saveDataStore:GetAsync(player.UserId)
	if data then
		print(data.Stage)
		for _, stat in pairs(_stats:GetChildren()) do
			stat.Value = data[stat.Name]
		end
	else
		print(player.Name .. " has no data")
	end
	
	player.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 = game.Workspace.ObbyStages:FindFirstChild(stage.Value)
				hrp.CFrame = part.CFrame + Vector3.new(0,1,0)
			end
		end
	end)
	
end)

players.PlayerRemoving:Connect(function(player)
	local err = savePlayerData(player)
	if err then print(err) end
end)

game:BindToClose(function()
	for _,player in pairs(players:GetPlayers()) do
		local err = savePlayerData(player)
		if err then print(err) end
	end
	wait(2)
end)
1 Like

Can you tell me what’s the name of folder with parts ?

Try this

local humanoid,hrp = char:WaitForChild("Humanoid"),char:WaitForChild("HumanoidRootPart")
wait()
if humanoid and hrp then
	if stage.Value ~= 0 then
		local part = game.Workspace.Stages:FindFirstChild(stage.Value)
		hrp.CFrame = part.CFrame + Vector3.new(0,1,0)
	end
end

Still not working, this is what I put.

1 Like