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

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

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

1 comment

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.

1 answer

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.

3 comments

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

0

if this somehow helps you here is a photo of my place - https://postimg.cc/0bYzgCfH

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

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