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

DataStore isn't working?[Reenactment of DataPersistence ]

I was searching for how to indirectly DataStore tools that the player had. I found a forum from a few years ago with jjwood1600 attempting DataStoring tools. Here is the whole forum:https://forum.roblox.com/Forum/ShowPost.aspx?PostID=155263528. So I used juniorj5's codes, near the bottom, and did his correction he showed, but it won't even find the ptools. I anyway I can fix this or get a better way to do it? I've been trying to find one but I can't find out how to. juniorjfive's Code:

tools = game:GetService("DataStoreService"):GetDataStore("Tools")
print(1)
game.Players.PlayerAdded:connect(function(pj)
	print(2)
local ptools = tools:GetAsync(tostring(pj.userId))
print(3)
print(4)
if ptools then
print(5)
for i, v in pairs(ptools) do
print(6)
game.ReplicatedStorage[v]:Clone().Parent = pj.Backpack
print(7)
end
end

end)

game.Players.PlayerRemoving:connect(function(pr)
local ptools = {}
for i, v in pairs(pr.Backpack:GetChildren()) do
table.insert(ptools, v.Name)
end
tools:SetAsync(tostring(pr.userId), ptools)
end)

The prints are for me to know which parts go through. It printed up to four, and nothing else shows(no errors or numbers) I constantly make stupid mistakes I'm sorry if I missed something obvious or this is outdated. Thank you in advance.

1 comment

1

If it prints to 4, ptools=nil. That would mean nothing is in the datastore

1 answer

Luke's answer is right the main problem is you haven't left yet to connect the save function, however there's also a problem that if you are either not storing your tools in ReplicatedStorage, or if the player has the tool selected, it moves to their character so you would have to make sure you also get any tools there.

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