Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Fix? Pls help error Portals Save System or DataStore for Portals

Asked by 2 years ago

PLS HELP

Code

    local dss = game:GetService("DataStoreService")
    local sv = dss:GetDataStore("Save1")

game.Players.PlayerAdded:Connect(function(plr)
    for i,v in pairs(game.Workspace.Teleports:GetChildren()) do
        local tp = v.Bought

        local data
        local succ, err = pcall(function()
            data = sv:GetAsync(plr.UserId, v.Bought.Value)
        end)

        if succ then
            tp.Value = data
            print("Succ")
        end
        end
end)
for i,v in pairs(game.Workspace.Teleports:GetChildren()) do
game.Players.PlayerRemoving:Connect(function(plr)
        local data = v.Bought.Value

        local succ,err = pcall(function()
            sv:SetAsync(plr.UserId.."_portal", v.Bought.Value)
        end)

        if succ then
            print("Data Saved")
        else
            print("Error Data")
            warn(err)
        end
    end)
end
0
Is this a localscript? I dont understand why you would need to do this in that way if its not game for only one player. BeautifulAuraLover 371 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Hello, I think I have identified the problem. I dont understand why you do data saving in this way, will only work on single player game, but thats your bussiness I guess. The problem was you were getting a sync from player.UserId but you were saving data like player.UserId_portal. I fixed the code for you. I recommend you to not copy code from internet and write it all yourself, because I cant imagine how you could make this error in other way.

local dss = game:GetService("DataStoreService")
local sv = dss:GetDataStore("Save1")

game.Players.PlayerAdded:Connect(function(plr)
    for i,v in pairs(game.Workspace.Teleports:GetChildren()) do
        local tp = v.Bought

        local data
        local succ, err = pcall(function()
            data = sv:GetAsync(plr.UserId, v.Bought.Value)
        end)

        if succ then
            tp.Value = data
            print("Succ")
        end
    end
end)
for i,v in pairs(game.Workspace.Teleports:GetChildren()) do
    game.Players.PlayerRemoving:Connect(function(plr)
        local data = v.Bought.Value

        local succ,err = pcall(function()
            sv:SetAsync(plr.UserId, v.Bought.Value)
        end)

        if succ then
            print("Data Saved")
        else
            print("Error Data")
            warn(err)
        end
    end)
end

Here is the fixed code. I wish you good luck in future with scripting, and I hope this helped.

0
I'm sorry this is my mistake when I wrote the code I put _Portal in "" I had this problem I deleted this text on the site and forgot to delete the text from line 24 because I thought it was not really necessary YTBrainBroYT 29 — 2y
0
if this somehow helps you here is a photo of my place - https://postimg.cc/0bYzgCfH YTBrainBroYT 29 — 2y
0
by the way, here is the error that comes out DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1744613578 YTBrainBroYT 29 — 2y
Ad

Answer this question