Can someone show me how I can make a Save Location system, or fix this

I put it in the command bar, it when I press enter it just highlights the whole cmd and does nothing. Sorry, I am not a scripter.

Leave the game, run the code and check the output. It should be white text.

You mean, rejoin the studio or stop the game and type it there, it does nothing btw.

Check the output, that’s why there is print there.

Bruhhhhh, I am an idiot, I wrote in the search bar server, to see if there are erros before and didn’t delete it. Btw it says this.

Try this. Publish the game and try it in the main game. Studio has some issues with data.

1 Like

I tried whatever you said, it still doesn;t work.

Is API services enabled? It HAS to be.

Yes, I always enable API services.

Let’s debug then…

local DataStore = game:GetService("DataStoreService")
local store = DataStore:GetDataStore("PlayerCharacterInfo", "PlayerPosition") --don't change the name of the DataStore or all data on it will be reset
local HTTPService = game:GetService("HTTPService")

local positions = {}

local function WaitForRequestBudget(budgetType)
    local request = pcall(function() return Enum.DataStoreRequestType[budgetType] end)
    if not request then return end
    if DataStore:GetRequestBudgetForRequestType(request) <= 0 then return end
    return true
end

local function save(player)
    if not WaitForRequestBudget("UpdateAsync") then
        repeat task.wait(3) until WaitForRequestBudget("UpdateAsync")
    end

    xpcall(function()
        store:UpdateAsync(tostring(player.UserId), function() return HTTPService:JSONEncode(positions[player]) end)
    end, function() warn(string.format("Error while saving %s's position!", player.Name)) end)

    positions[player] = nil
end

game.Players.PlayerAdded:Connect(function(player)
    local position = pcall(function()
        return HTTPService:JSONDecode(store:GetAsync(tostring(player.UserId)))
    end)
    if not position then return end
	player.CharacterAdded:Once(function(character)
        character:PivotTo(CFrame.new(position[1], position[2], position[3]))
        character.HumanoidRootPart:GetPropertyChangedSignal("CFrame"):Connect(function()
            positions[player] = {character:GetPivot()[1], character:GetPivot()[2], character:GetPivot()[3]}
            print("Debug:", table.concat(positions[player], ", ")
        end)
    end)
end)

game.Players.PlayerRemoving:Connect(save)

game:BindToClose(function()
    for _, v in game.Players:GetPlayers() do
        task.spawn(save, v)
        print(string.format("Saving %s's data!", v.Name))
    end
    task.wait(15)
end)

It got 2 errors here.
image
image

Typo. Just add ) next to the print.

Now it has this error.
image

That’s wrong… I edited my code so just paste it.

It’s the same code btw. You didn’t edit it yet.

I did, it was a minor typo but you ended up adding a wrong part which you won’t understand.

Reply, to the script. You mean the one that you sent me above, that’s the same.

Here.
It’s a one character difference which fixes the error.

It doesn’t work, no erros but still doesn’t work.

It should print in the output.