I made a obby data store doesnt work

Ok so here is my script

local DataStoreService = game:GetService(“DataStoreService”)
local StageDataStore = DataStoreService:GetDataStore(“StageData”)

local function TouchedPart(part, touchedPart)
local ply = game.Players:GetPlayerFromCharacter(touchedPart.Parent)
if ply then
if ply.leaderstats.Stage.Value < tonumber(part.Name) then
ply.leaderstats.Stage.Value = tonumber(part.Name)
end
end
end

local function AddTouchStageGiver()
local stageNum = 1
while true do
local part = game.Workspace:FindFirstChild(tostring(stageNum))
if part then
part.Touched:connect(function (touchedPart)
TouchedPart(part, touchedPart)
end)
else
break
end
stageNum = stageNum + 1
wait()
end
end

local function GetSavedStage(ply)
return StageDataStore:GetAsync(tostring(ply.UserId)) or 1
end

local function SaveCurrentStage(ply)
StageDataStore:SetAsync(tostring(ply.UserId), ply.leaderstats.Stage.Value)
end

local SPAWN_OFFSET = Vector3.new(0, 5, 0)

local function GetStageSpawnCFrames(stage)
local stageSpawnPart = game.Workspace:FindFirstChild(tostring(stage))

if not stageSpawnPart then
	return game.Workspace:FindFirstChild("1").CFrame + SPAWN_OFFSET
end

return stageSpawnPart.CFrame + SPAWN_OFFSET

end

local stageValues = {}

local function CharacterAdded(ply, char)
repeat wait() until stageValues[ply]
char:SetPrimaryPartCFrame(GetStageSpawnCFrames(stageValues[ply].Value))
end

game.Players.PlayerAdded:connect(function (ply)
local leaderstats = Instance.new(“ObjectValue”, ply)
leaderstats.Name = “leaderstats”

ply.CharacterAdded:connect(function (char)
	CharacterAdded(ply, char)
end)

local stage = Instance.new("IntValue", leaderstats)
stage.Name = "Stage"
stage.Value = GetSavedStage(ply)

stageValues[ply] = stage	

--[[
if ply.Character then
	CharacterAdded(ply, ply.Character)
end
--]]

end)

game.Players.PlayerRemoving:connect(function (ply)
SaveCurrentStage(ply)
end)

wait(1)
AddTouchStageGiver()


and here is the script I’m using on my checkpoints

function ot(hit)
if hit.Parent ~= nil then
local player = game.Players:playerFromCharacter(hit.Parent)
if player ~= nil then
if player.leaderstats.Stage.Value == script.Parent.Name - 1 then
local h = hit.Parent:FindFirstChild(“Humanoid”)
if h ~= nil then
if h.Health ~= 0 then
player.leaderstats.Stage.Value = script.Parent.Name
end end end end end end

script.Parent.Touched:connect(ot)


and

local spawn = script.Parent
spawn.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild(“Humanoid”) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local checkpointData = game.ServerStorage:FindFirstChild(“CheckpointData”)
if not checkpointData then
checkpointData = Instance.new(“Model”, game.ServerStorage)
checkpointData.Name = “CheckpointData”
end

	local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
	if not checkpoint then
		checkpoint = Instance.new("ObjectValue", checkpointData)
		checkpoint.Name = tostring(player.userId)

		player.CharacterAdded:connect(function(character)
			wait()
			character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
		end)
	end

	checkpoint.Value = spawn
end

end)
and what its supposed to do is save the checkpoint like if you leave and rejoin you will be in the same position

This is painful to look at but it looks like you’re doing everything correct, if you’re in studio:

game:BindToClose(function() wait(20) end);

Else if you’re in the actual game, I’ll have to take a closer look.

I’m not sure what to do I’m new to scripting and this is ingame its not saving it doesnt save in studios either

maybe you haven’t turned on the API service

where is that located I’m very new to scripting

Never mind i figured it out thanks i think this will do the trick

so does it work?

(ignore this)

No sadly it wasn’t the case thanks for asking
I think its to do with my script

theres no problem with your script

Wait where do i put it in serverscriptservice right?

yeah also
The datastore only works in-game

that i know already i haven’t tried testing it in studio