local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
game.Players.PlayerAdded:Connect(function(plr)
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local tools = {}
local tools_folder = plr_leave:FindFirstChild("Tools_Folder")
for _, eachtool in pairs(tools_folder:GetChildren()) do
table.insert(tools , eachtool.Name)
end
local success , error = pcall(function()
return toolsdata:SetAsync(plr_leave.UserId , tools)
end)
if not success then
warn(plr_leave.Name .."Didn't save tools data: ".. error)
end
end)
```Here idk why tools come to toolsfolder but not backpack
#Tool data store
1 messages · Page 1 of 1 (latest)
Not sure if the newtool_folder is supposed to clone the tool
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
he just creates 2 variables cause he didnt know how to else to clone it 2 times thats why its like this prolly, but that part is correct
@raw mantle did you check the explorer if the player has the tool there?
ok i will delete first clone and keep backpack to see if its problem
no thats fine
yep still
tool:Clone().Parent = tools_folder
tool:Clone().Parent = Backpack
y could just simplify it
and when i say print backpack getchildern output: [1] = Tool
ok i will try
look at the explorer and go into the backpack
no tool apear
hm
yep this is what makes my brain error lol
wait make the tool a variable
and then print the tool to see where it is and after parenting it print it again
this way we can see if it clones right
and parents right
ok u mean i do print newtool_back.parent ?
local backpackTool = tool:Clone()
tool:Clone().Parent = tools_folder
print(backpackTool)
backpackTool.Parent = Backpack
print(backpackTool)
like this
if tool then
tool:Clone().Parent = tools_folder
tool:Clone().Parent = Backpack
end
```i edit this part
paste this to debug
ok wit i delete what i do
if tool then
local backpackTool = tool:Clone()
tool:Clone().Parent = tools_folder
print(backpackTool)
backpackTool.Parent = Backpack
print(backpackTool)
end
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
print(newtool_back.Parent)
newtool_back.Parent = Backpack
print(newtool_back.Parent)
end
end
end
```like this ?
yes
oh
and now see where its located before and after
output nothing
then the folder isnt working aswell
oh wit there is no data i will resave it
output: nil
output: Backpack
hooow Y_Y
i print backpack.parent ?
ok idk what is problem is it bug ? @honest dove
nono just print newtool_back not the parent
but i think how you are trying to save ur tools is the problem
when player leave u mean ?
you cant actually save the whole tool you have to give every tool an ID save the IDs and then wehn it loads you have to convert these IDs to the tools again
you can only save tables, strings, bools, numbers
no tools/instances
uhmm idk this is problem and i save tools.name
o
table.insert(tools , eachtool.Name)
wait
ok
mb ur correct
i am sure that problem not when player leave bec when i test tool.parent = folder_tools and its tool
but dont go to backpackk
okay so i want you to print newtool_back now
and not the parent
so we can see if it clones and where its then located and where its located after parenting
it will print the tool instance
and wehn you click it it will show you the position of it in the explorer
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
print(newtool_back)
newtool_back.Parent = Backpack
print(newtool_back)
end
like this ?
all good
so it doesnt show the tool in the explorer
nope
Can i give u game files so u can see problem better ?
this game i didnt do any thing on it lol
alr
ohh i see maybe problem
print(newtool_back.Parent)
Here output backpack but when i press it nothing apear
that means backpack is nil too
local Backpack = plr:FindFirstChildOfClass("Backpack") or plr:WaitForChild("Backpack")
try this
just asking but have you tried putting the tool in the character
yep no change
because im pretty sure its going to do what you want
what u mean ?
u mean put tool for example in my player name ?
like get the player's character and put the tool there
** You are now Level 6! **
i mean thats a workaround but the save wont work then
idk if its possible bec when plr join there is only 4 things on it StraterGear , Backpack , and other thing
wait how long have you been scripting?
because that is not true
if i want the humanoid or anything inside charcter then i could make charcter but backpack not inside charcter
he meant that you just put the tools in your char
this works
but will completly fuck up your saving
I wanna know why it wont work in the backpack tho
it works inside folder and goes to it but backpack nope
ok so what i do is local charc = plr.cha......
and then put newtool_back.parent = char ?
ig but it would make the player equip it on added
and adding multiple would break it
so
uhh
ohh wit !!
newtool_back.Parent = game.StarterPack
here its goes to starterpack
soo problem in backpack not clone
newtool_back.Parent = plr:FindFirstChild("Backpack") or plr:WaitForChild("Backpack")
also this dont work
i will just keep it at folder maybe there is bug
ok how about just put a breakpoint and see if anything goes wrong
i forgot to tell u , 15-20 days
the tools_table has nothing in it or the if statements catch something
mb u where right the char wont break shit
and startpack also just puts it in the char
but why the hell wont the backpack work
ok i have diffrante idea maybe roblox do when player join i cant give tool to backpack soo i will add diffrante script and put task.wait(1) then add this tool
if it worked soo there was a bug
is this a local or a server script just asking
server
i already tried that that works
oh so its a stupid roblox bug lol
i don't think so
i also dont think so the problem is in how your getting the backpack
im trying to figure it out rn
whats ur code now fake_name1?
is there any other way to call back pack not from player ?
same
it works so problem here is on backpack bec when i say print backpack and press it nothing happen
local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
game.Players.PlayerAdded:Connect(function(plr)
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
print(success)
print(toolstable)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
print("passed nil tool check")
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
end
end
end
end)
``` just try this and see what the prints are
i dont think its something to do with the backpack
ok output is:
it legit has 😭
wait was the toolstable print empty
True
{
[1] = Tool
}
passed nil tool check
this is output
wait can we have the whole code again
?
like the script
i do or u do ?
your code
local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
game.Players.PlayerAdded:Connect(function(plr)
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local tools = {}
local tools_folder = plr_leave:FindFirstChild("Tools_Folder")
for _, eachtool in pairs(tools_folder:GetChildren()) do
table.insert(tools , eachtool.Name)
end
local success , error = pcall(function()
return toolsdata:SetAsync(plr_leave.UserId , tools)
end)
if not success then
warn(plr_leave.Name .."Didn't save tools data: ".. error)
end
end)
```this ?
yeah that
wait no
the newest one
not the old one
new one is only print to knnow where tools locate
and tools. parent = nil
when i print(backpack) and click on it nothing happen so tat means backpack also nil
local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
game.Players.PlayerAdded:Connect(function(plr)
local tf = Instance.new("Folder")
tf.Name = "Tools_Folder"
tf.Parent = plr
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
task.spawn(function()
task.wait(5)
newtool_back.Parent = plr.Backpack
end)
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local tools = {}
local tools_folder = plr_leave:FindFirstChild("Tools_Folder")
for _, eachtool in pairs(tools_folder:GetChildren()) do
table.insert(tools , eachtool.Name)
end
local success , error = pcall(function()
return toolsdata:SetAsync(plr_leave.UserId , tools)
end)
if not success then
warn(plr_leave.Name .."Didn't save tools data: ".. error)
end
end)
this works and i have no idea why it does
what
i dare u guys found problem
local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local tools = {}
local tools_folder = plr_leave:FindFirstChild("Tools_Folder")
for _, eachtool in pairs(tools_folder:GetChildren()) do
table.insert(tools , eachtool.Name)
end
local success , error = pcall(function()
return toolsdata:SetAsync(plr_leave.UserId , tools)
end)
if not success then
warn(plr_leave.Name .."Didn't save tools data: ".. error)
end
end)
task.wait(2) make it work when player added Y_Y
i will really cry
thats what i legit just said
but how and i say :WaitForChild ?
idk why but its a diffrent backpack wehn you instantly get the backpack and 1 second later
@royal canyon do you know why this happens?
who @royal canyon ?
very good scripter and also very got at explaining it
no but using task.wait() should'nt change anything
game.Players.PlayerAdded:Connect(function(plr)
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local newTool = Instance.new("Tool")
newTool.Parent = Backpack
end)
this works
ysry read this
this shouldnt work actually
it does though
oh i change task.wait(1) and didnt work so i must write task.wait(2) ?
local datastoreservice = game:GetService("DataStoreService")
game.Players.PlayerAdded:Connect(function(plr)
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local tool = game.ServerStorage.Folder:FindFirstChild("Tool")
tool:Clone().Parent = Backpack
end)
and this doesnt work again 😭
ohh maybe i know problem
this doesnt make any sense
ok i know
works for me
this doesnt even work
oh but i use wait so idk why
it doesnt work for me
yep same
this aint making any sense ong
ok problem that game need like 2 sec to load plr backpack ?
yep i was right its a bug !!!
so i just keep task.wait(2) ? bec task.wait(1) dont want to work too
no it finds it but after 2 secs its not the exact same backpack
so im assuming the backpack parenting works fine but it gets deleted and recreated?
yes hoow this will blow my mind
maybe instead just wait for the players character to load before declaring any variables
or doing anything really
how will this fix that we are waiting for the backpack to load with WaitForChild
problem that when i say task.wait(1) didnt work and charcter spawn in less than 1 sec
without waitforchild it has suggested code but with waitforchild it doesn't
game.Players.PlayerAdded:Connect(function(plr)
local tf = Instance.new("Folder")
tf.Name = "Tools_Folder"
tf.Parent = plr
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local newTool = Instance.new("Tool")
newTool.Parent = Backpack
end)
this doesnt work
and its just worth a shot
game.Players.PlayerAdded:Connect(function(plr)
task.wait(2)
local tf = Instance.new("Folder")
tf.Name = "Tools_Folder"
tf.Parent = plr
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local newTool = Instance.new("Tool")
newTool.Parent = Backpack
end)
and this does
but its legit printing the backpack 😭
now try task.wait(1) lol
the problem that its same backpack Y_Y
idk why this happen to me when i start learn tool data store
FUCK I KNOW WHATS THE PROBLEM IS
THE CLIENT HASNT CREATED ITS BACKPACK YET THATS WHY IT FAILS
maybe because adding a tool to a backpack that the character requires is impossible because the character doesn't exist yet
but i say Wait
and waitforchild doesn't work for that
look the server creates the backpack but then the client creates the backpack which ig overwrites the servers backpack
** You are now Level 21! **

why would the client create a backpack
you are waiting for the server backpack with :WaitForChild
idk 😭
thats the only solution that makes sense
okk i will just stick with task.wait(2) there is nothing else we can do
if the client made the backpack it wouldn't show for the server so why would waiting 2 seconds work
and when i go to ai it says it should work without task.wait()
yes and why waiting 1 sec not work
try just do .Backpack and remove the task.wait()
and wait for child ?
remove the waitforchild too
uhmm ok
game.Players.PlayerAdded:Connect(function(plr)
local tf = Instance.new("Folder")
tf.Name = "Tools_Folder"
tf.Parent = plr
local backpack1 = plr:WaitForChild("Backpack")
print("Backpack 1:", backpack1)
task.wait(2)
local backpack2 = plr:FindFirstChild("Backpack")
print("Backpack 2:", backpack2)
print("Same?", backpack1 == backpack2)
end)
my theory is correct
yep no tool inside backpack
ohh
but how Y_Y
idk
roblox studio is suck
chatgpt said it could be a temporary backpack and roblox replaces it afterwards
yes but why like server create backpack then delete it , it doesnt make sense
ima make a new thread for this and ask if anyone is aware of this problem
i dont want to blow my mind more i just too happy that i solve it
oh wit @royal canyon with us
@royal canyon can u help us on that ?
nope its just this thread that proves my theory correct: https://devforum.roblox.com/t/tool-wont-be-added-in-backpack-when-player-joins/2229215
Developer Forum | Roblox
You can write your topic however you want, but you need to answer these questions: What do you want to achieve? Keep it simple and clear! I want to make it so that after the character does an animation(with tool 1 which should spawn in with you) infront of a part. The part gives tool number 2 to the player. What is the issue? Include scre...
ooo
Just wait for the player's character to load
that makes sense so roblox deletes the backpack and recreates it wehnever the character reloads / in our scenario first loads
that also explains why we cant compare them
and waiting 2 seconds doesn't completely fix it because of different loading times
ohhhhh
local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
game.Players.PlayerAdded:Connect(function(plr)
local charcter = plr.Character or plr.CharacterAdded:Wait()
if charcter then
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local tools = {}
local tools_folder = plr_leave:FindFirstChild("Tools_Folder")
for _, eachtool in pairs(tools_folder:GetChildren()) do
table.insert(tools , eachtool.Name)
end
local success , error = pcall(function()
return toolsdata:SetAsync(plr_leave.UserId , tools)
end)
if not success then
warn(plr_leave.Name .."Didn't save tools data: ".. error)
end
end)
this work so yeah i need to wait charcter to load
lol
you don't need the if character btw
because you're waiting for it already
what if it never loads
hoow ?
then characterAdded:Wait() will never end
like when u join game u must load or roblox kick u right ?
ig
so i change or to and ?
oh and you spelt character wrong
oh lol
but finnaly it worked
tysm guys
But
this code will work fine like its ? /10 ?
i would use profileStore but it should work at like a solid 6/10
i did other one for leaderstats
when i go to profile store i got shocked and leave it
profile service is just a more secure method but it also uses DataStoreService so if you use DataStoreService correct it doesnt really make a diffrence
it needs module
and i understand way of module but when i use it my brain start to get errors
its pretty simple
then i will make it every 60 sec save plr to make u rate me higher lol
it was also confusing at the start for me but its really helpful for making things organized
I also do that then nothing should go wrong
i know it is confusing at first so i will wait like 1 year practise script then go to it
nah with your knowledge you should be able to learn them
it should reduce people losing save data but do it less often (eg 10-5m)
yep but problem is source
like i cant read 3 pages to understand it
oh not every 60 sec ?
no
ok
and thats what i meant with expandable
this is what i use as my datastore
it doesnt work for tools tho might have to rewrite that
or arrays at all actually
yeah but bro its very goood
** You are now Level 19! **
like i cant understand the script lol
yeah the loops are pretty nested
but it just saves/loads data from the dataTree thats all
u use module script ?
yeah these are both module scripts
local SSS = game:GetService("ServerScriptService")
local MDLS = SSS:WaitForChild("Modules")
local dataService = require(MDLS.dataService)
PLRS.PlayerAdded:Connect(function(plr)
dataService:_initPlayer(plr)
end)
PLRS.PlayerRemoving:Connect(function(plr)
dataService.dataSave(plr)
end)
game:BindToClose(function()
for i,v in pairs(game.Players:GetPlayers()) do
dataService.dataSave(v)
end
end)
task.spawn(function()
while true do
task.wait(60)
for _, plr in pairs(game.Players:GetPlayers()) do
dataService.dataSave(plr)
end
end
end)
i would run them like this
wait does yours reconcile
local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
local runservice = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function(plr)
local waittime = 0
local Character = plr.Character or plr.CharacterAdded:Wait()
if Character then
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
end
end
end
local tools = {}
runservice.Heartbeat:Connect(function(deltatime)
waittime += deltatime
if waittime >= 60*5 then
waittime = 0
if plr.Parent ~= nil then
for _, eachtool in pairs(tools_folder:GetChildren()) do
table.insert(tools , eachtool.Name)
end
local success , error = pcall(function()
return toolsdata:SetAsync(plr.UserId , tools)
end)
if not success then
warn(plr.Name .."Didn't save tools data: ".. error)
end
end
end
end)
end
end)
this will work fine right ?
oh i forgot to add disconnct
60 * 5 = 300 btw
** You are now Level 7! **
yep i know for sure lol
wdym
but if i want to make it like 7 , 8 i think that i will do local min = 1
Why have I been @ed 4 times?
we figured it out mb 😭
local datastoreservice = game:GetService("DataStoreService")
local toolsdata = datastoreservice:GetDataStore("toolsdata")
local runservice = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function(plr)
local waittime = 0
local Character = plr.Character or plr.CharacterAdded:Wait()
if Character then
local tools_folder = plr:WaitForChild("Tools_Folder")
local Backpack = plr:WaitForChild("Backpack")
local success , toolstable = pcall(function()
return toolsdata:GetAsync(plr.UserId)
end)
if success and toolstable then
for _ , eachtool in pairs(toolstable) do
local tool = game.ServerStorage.Folder:FindFirstChild(eachtool)
if tool then
local newtool_folder = tool:Clone()
local newtool_back = tool:Clone()
newtool_folder.Parent = tools_folder
newtool_back.Parent = Backpack
end
end
end
local tools = {}
local connect
connect = runservice.Heartbeat:Connect(function(deltatime)
waittime += deltatime
if waittime >= 60*5 then
waittime = 0
if plr.Parent ~= nil then
for _, eachtool in pairs(tools_folder:GetChildren()) do
table.insert(tools , eachtool.Name)
end
local success , error = pcall(function()
return toolsdata:SetAsync(plr.UserId , tools)
end)
if not success then
warn(plr.Name .."Didn't save tools data: ".. error)
end
else
connect.Disconnect()
end
end
end)
end
end)
this will work fine ?
I'm a Never Nester and you should too.
Access to code examples, discord, song names and more at https://www.patreon.com/codeaesthetic
Correction: At 2:20 the inversion should be "less than or equal", not "less than"
wtf
i would recommend you to watch the video
the stuff ziffix sends is actually pretty useful
alr fake_name1 gl on your scripting journy ima go now
okk cya ty for helping
@royal canyon ty alot this video make me learn alot of things
told ya hes great
yep
function dataService:_initPlayer(plr)
local data = dataService:_loadPlayerData(plr)
for i, folder in dataTree.Folders do
dataService:_createFolder(plr, folder, data)
end
end
function dataService:_loadPlayerData(plr)
if not dataTree.DataStoreName then return end
local success, result = pcall(function()
DSS:GetDataStore(dataTree.DataStoreName):GetAsync(plr.UserId)
end)
return success and result or {}
end
function dataService:_createFolder(plr, folderDef, data)
local newFolder = Instance.new("Folder")
newFolder.Name = folderDef.Name
newFolder.Parent = plr
for i, value in folderDef.Values do
dataService:_createValue(value, newFolder, data)
end
end
function dataService:_createValue(valueDef, newFolder, data)
local value = Instance.new(valueDef.Instance)
value.Name = valueDef.Name
if data and valueDef.Save and data[valueDef.Name] then
value.Value = data[valueDef.Name]
else
value.Value = valueDef.StartValue
end
value.Parent = newFolder
end
i already unnested the load section
broo dont make me watch those module script
ohh i have really really bad thing
my memory usage is 2409MB Y_Y @honest dove
and my game is very very basic
https://github.com/zyosqq/Roblox/blob/main/DataService/dataService.lua @raw mantle im finished what do y think
just fps and when plr buy toon then gives item all those 2409mb
o
there is way i can show u my game ?
