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

How to make obby checkpoints which save your data so when you rejoin you restart there?

Would I add a script into the checkpoints, ServerScriptService or anywhere else which saves the players data? Like in "THE IMPOSSIBLE OBBY". If so, can I get some help?

2 answers

✓ Accepted answer

You can achieve this by using simple DataStore

First you want to make the checkpoint and spawn when player joins. P.S: The spawn when player joins is optional. In my script I'm making it saves everytime players touch the checkpoint

Make Event in ReplicatedStorage called anything. In my script, I'm naming it SendData

LOCAL SCRIPT: ( Put this in StarterPlayerScript )

local Workspace = game:GetService("Workspace")
local plr = game.Players.LocalPlayer

local Checkpoints = Workspace.Check1 -- Define your checkpoints
local Stage = 1

local deb = false
local function sendDataToServer(hit)
	if plr.Stage.Value < 1 then -- for safety reason ( so player from higher stage wont lose their progress )
		if deb == false then
			deb = true
			
			local Event = game:GetService("ReplicatedStorage").SendData -- Your event
			if Event then
				Event:FireServer(hit.Parent.Name, Stage)
			end
			wait(3)
			deb = false
		end
	end
end

Checkpoints.Touched:Connect(sendDataToServer)

After that make a script in ServerScriptService

SERVER SCRIPT:

local DataStore = game:GetService("DataStoreService")
local stageDataStore = DataStore:GetDataStore("stageDataStore") -- your datastore
local WS = game:GetService("Workspace")

game.Players.PlayerAdded:Connect(function(plr)
	local Stage = Instance.new("NumberValue")
	Stage.Name = "Stage"
	Stage.Parent = plr
	
	local data = stageDataStore:GetAsync(plr.UserId)
	if data then
		plr.Stage.Value = data
		print("data loaded")
		-- loading player to checkpoint
		if plr.Stage.Value == 1 then -- this is the 1st checkpoint
			local character = plr.Character
			if character then
				local humrootpart = character:WaitForChild("HumanoidRootPart")
				humrootpart.CFrame = WS.Check1.CFrame
			end	
		end
	end
end)

local RS = game:GetService("ReplicatedStorage")


local function savePlayerData(plr, checkpoint) -- saves player data
	local player = game.Players:FindFirstChild(plr)
	
	player.Stage.Value = checkpoint
	local data
	data = player.Stage.Value
	
	stageDataStore:SetAsync(player.UserId, data)
end


RS.SendData.OnServerEvent:Connect(function(_, player, checkpoint)
	savePlayerData(player, checkpoint)
end)

-- This line is for: when player dies they respawn in the checkpoint
game.Players.PlayerAdded:Connect(function(plr)
        local checkpoint = plr.Stage.Value
        plr.CharacterAdded:Connect(function(char)
                while wait() do
                       local HRP = char:WaitForChild("HumanoidRootPart")
                       if checkpoint == 1 then
                              HRP.CFrame = WS.Check1.CFrame
                       end
                       if checkpoint HRP.CFrame = WS.Check1.CFrame then
                              break
                       end
                end
        end)
end)

If you want to make more than 1 checkpoint, copy line 7-23 and make local Checkpoints as a table and add new checkpoint inside. Let me know if this works! I am not an expert in scripting, so expect for some errors! I am sure there are better ways to do this but this is what I am using. Thank you.

1 comment

0

Sorry for line 44-57 in serverscript. I just realized I didn't put player respawn function after dying, so it's little bit messy.

Use this script: Loader:Connect.OnLaunch = local Load.(567887456789865)

1 comment

0

That doesn't work for 1, and 2, don't suggest external sources. They often contain viruses

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