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

Okay, so what can i do so I can have a fully workable save location script that is simple. With the code above

I really do not want to use the code you sent since it is VERY unreliable.

You’re setting the data every 0.03 seconds and roblox has a rate limit which makes it unable to save any other data.

Also, the “joined” boolean only works for the first person.
It doesn’t work for multiple players.

You don’t even use pcalls which makes the script prone to errors.

So, can you give me a script that works perfectly. Only save location when someone is somwhere and when he leaves from the game and rejoins, he will be teleported back.

I can’t just give a perfect script, it might not always work the first time. I will give my script and we’ll work with that.

Also, check if API is enabled, go to game settings → security

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 positions = {}

local function WaitForRequestBudget(budgetType)
    local request = pcall(function() return Enum.DataStoreRequestType[budgetType] end)
    if not request 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 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 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]}
        end)
    end)
end)

game.Players.PlayerRemoving:Connect(save)

game:BindToClose(function()
    for _, v in game.Players:GetPlayers() do
        task.spawn(save, v)
    end
    task.wait(15)
end)

How long does it take to save the position? I prefer 3-4 seconds.

It saves when the player leaves, I can add auto save though. However, auto save is pretty unreliable for 3-4 seconds. 45-60 seconds is good for auto-save.

If it’s 45 secs or 20 it’s bad because I am making an rp and they will spawn somewhere else if the location doesn’t save.

Do you want to save location when player leaves and rejoins or save mid-game?

Save players location whn the players leaves and rejoins. But faster cause it’s bad every 30 or 20 secs.

It saves when the player leaves and rejoins, it’s already pretty reliable so you don’t need to push it.

Just know that autosave should be 45-60 seconds. Any less makes it quite unreliable.

Yes, but I’ve seen some rp’s that the ocation script is pretty good without problems and it saves like every 2 or 3 secs. But I want it fast and workable.

I don’t see the need to push it. Like I said, auto-save is unreliable with 2-3 seconds. They use an advanced module for that.

Just stick to the script please.
We won’t be going anywhere if you don’t.

Okay, the script that you sent me hs like 4 or 5 errors.

Show me them please.

You can type them.

Line 8 return error
Line 25 game Error
Line 44 task.wait(15) error
line 45 end) error

Check the script that you sent above.

 if not request return end
--------------------
game.Players.PlayerAdded:Connect(function(player)
---------------------
    task.wait(15)
-----------------
end)

I don’t really see what the error is. You can take a screenshot since you’re not really typing the ‘Error Code’

Screenshot of the script or output?



here

Screenshot the errors please, the errors you’re typing are quite vague.

I mean the errors in the output.

For the return error, just add ‘then’ before ‘return’.

if not request then return end

I’m on mobile, so I can easily make typos.

It shows me only this error here.


You just told me what to do ok but there are 3 more errors it says but I cant see any of them in the output.

Yep, just do the fix I showed right above.