How fix problem in obby


When I enter the game, I appear at the beginning, when I press reset, I appear at stage 19.

-- :3
--DataStore--
local ds = game:GetService("DataStoreService"):GetDataStore("StatsStore4")

game.Players.PlayerAdded:Connect(function(player)
	print("connected")
	local playerFolder = Instance.new("Folder")
		playerFolder.Name = "leaderstats"
		playerFolder.Parent = player

	local ack2 = Instance.new("IntValue")
		ack2.Name = "Stage"
		ack2.Value = 1
		ack2.Parent = playerFolder
--loaddata	
	local savestuff = ds:GetAsync(player.UserId)	
	--print("data takes up ".. game:GetService("HttpService"):JSONEncode(savestuff):len().. "/260000")
local StatsFile = player.leaderstats
	if savestuff then
		for i,v in pairs(savestuff) do
			if i % 2 == 0 then
				StatsFile:FindFirstChild(savestuff[i - 1]).Value = v
				
			end
		end
		
	end
end)

local function saveValues(player)
	local saveData = {}
	local StatsFile = player.leaderstats

	for i,v in pairs(StatsFile:GetChildren()) do
			saveData[#saveData + 1] = v.Name
			saveData[#saveData + 1] = v.Value
	end
	ds:SetAsync(player.UserId, saveData)
end

game:BindToClose(function()
	for i, player in pairs(game.Players:GetPlayers()) do
		saveValues(player)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	saveValues(player)
end)





function oa(object)
	local player = game.Players:playerFromCharacter(object)
	if player ~= nil then
		local ls = player.leaderstats
		local sl = game.Workspace.Checkpoints:FindFirstChild(ls.Stage.Value)
		print("gah")
		wait(2)
		object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
		object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
	end 
end
game.Workspace.ChildAdded:connect(oa)
3 Likes

Thank you for help DevForum nice

The player HRP CFrame is to the teleport part CFrame so try rotate it.

Make sure that there isnt any spawn location that is making you spawn in there

nothing. only checkpoints/////

Shouldn’t it be game.Workspace.ChildAdded:connect(oa()) or am i just being dumb? And where is the parameter for the object?

I changed but the problem is the same

What do you mean? i’m confused

That literally doesn’t solve the problem

Also do you always spawn at the beginning and then spawn in a stage you were in?

When I join the game, I’m at the beginning, when they reset the character, I appear at the stage where I was, and then everything is fine.

If you look at the picture in the bottom right, it says to reset if you are not on your stage. The code is working as intended, as I assume you took this from a freemodel.

Are you getting any errors? If so then that might be the case

Yes, I took it because I’m just a 3Modeler and not a programmer

What are you trying to achieve here? Are you wanting the player to move to the last stage they were at when they join the game, are you trying to get the player to go the beginning when they reset their character?

Taking freemodels is fine, especially for learning scripting. There’s no shame in using them, though it’s good practice not to when you become better at scripting. So what exactly do you want to fix? Do you want to reset and stay at stage 1? Do you want to spawn at the stage you’re at?

The game has a date store for saving checkpoints, and I reached stage 19, re-entered and I appeared at the beginning, although stage 19 is written in the corner, and when I reset a character I appear at stage 19.

Freescripts*, i don’t like learning scripts, and i don’t have lot time

So you want the player to go straight to stage 19(or the stage they were last at) when they join the game?

Then i would recommend you hire one. Its what makes your games fun