Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a save postion Script for my obby, with the stage levels.?

Hi there, a Mom here trying to make a game with my boys. lol

trying to make an Obby. One that when you leave, it saves your current position from when you last played, and the stage you were on.

This is the script that saves my last position I placed in "Server Script Service"

local ds = game:GetService("DataStoreService")
local dsl = ds:GetDataStore("positionsave") 

game.Players.PlayerAdded:Connect(function(p)
	local pos = Instance.new("Vector3Value",p)
	pos.Name = "Position"
	local userdata
	pcall(function()
		userdata = dsl:GetAsync(p.UserId)
	end)
	if userdata then
		game.Workspace:WaitForChild(p.Name):WaitForChild("HumanoidRootPart").CFrame = CFrame.new(userdata[1], userdata[2],userdata[3])
	else	
		dsl:SetAsync(p.UserId,{ 0, 3, 0})
	end
end)

game.Players.PlayerRemoving:Connect(function(p)
		
		
		dsl:SetAsync(p.UserId, {
		math.floor(p.Position.Value.X),
		math.floor(p.Position.Value.Y),
		math.floor(p.Position.Value.Z)
		})
			
			
end)

game.Players.PlayerAdded:Connect(function(p)
	local pos = p:WaitForChild("Position")
	p.CharacterAdded:Connect(function(char)
		while true do
			pos.Value = char:WaitForChild("HumanoidRootPart").Position
			wait(1)
		end
	end)
end)

So YES it works on saving my position, but SAY I was on Stage 2 and leave the game, When rejoining it loaded my character onto Stage 2, but it said Stage 0 in my leaderboard,
I need help with a script, for my obby, that saves my players position and the stage they were last on.

Here is my Checkpoint Script that is placed in my "Workspace"

local STAT_NAME = "Stage"
local PREVENT_SKIPPING = true

local checkpoints = {}

local i = 1
while true do
	local checkpoint = Workspace:FindFirstChild("Checkpoint " .. i, true)
	if not checkpoint then print("Last Checkpoint : " .. i-1) break end
	table.insert(checkpoints, checkpoint)
	i = i + 1
end

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Model", player)
	leaderstats.Name = "leaderstats"
	
	local checkpointStat = Instance.new("IntValue", leaderstats)
	checkpointStat.Name = STAT_NAME
	checkpointStat.Value = 0
	
	player.CharacterAdded:connect(function(character)
		local goto = checkpoints[checkpointStat.Value]
		if goto then
			repeat wait() until character.Parent
			character:MoveTo(goto.Position)
		else
			warn("Checkpoint " .. checkpointStat.Value .. " not found")
		end
	end)
end)

for index, checkpoint in ipairs(checkpoints) do
	checkpoint.Touched:connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not player then return end
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if not humanoid or humanoid.Health <= 0 then return end
		local leaderstats = player:FindFirstChild("leaderstats")
		if not leaderstats then return end
		local checkpointStat = leaderstats:FindFirstChild(STAT_NAME)
		if not leaderstats then return end
		
		if (PREVENT_SKIPPING and checkpointStat.Value + 1 == index) or (not PREVENT_SKIPPING and checkpointStat.Value < index) then
			checkpointStat.Value = index
		end
	end)
end


1 comment

0

Please use codeblocks.

1 answer

✓ Accepted answer

It looks like you are saving the Player's position, but I don't see where you save what level they are on. Nothing in Roblox is persistent without using a DataStore, so you are also going to have to establish a system to save that data as well.

This discussion is preserved as it was. New answers, comments, and votes are closed.