#This script is working but
129 messages · Page 1 of 1 (latest)
if ToolFolder:FindFirstChild(v) and backpack:FindFirstChild(v) == nil
The meaning of this is : "If the tool is a child of ToolFolder, and is not a child of backpack then add it in the backpack"
At the first iteration the tool will be added
but at the 2nd
backpack:FindFirstChild(v) will be true and not nil
because it's added
how do I fix it
remove this ``and StarterGear:FindFirstChild(v) == nil`
i forgot to tell you abt this but removing it should work
ima go try
i think you should learn a bit more about coding before actually follow a tutorial
i guess you want to make a game
ye 😅
local ToolFolder = game:GetService('ServerStorage'):FindFirstChild('Saved fruits')
local DataStoreService = game:GetService('DataStoreService')
local SavedData = DataStoreService:GetDataStore('SaveData')
game.Players.PlayerAdded:Connect(function(player)
local ToolData = SavedData:GetAsync(player.UserId)
local backpack = player:WaitForChild('Backpack')
local StarterGear = player:WaitForChild('StarterGear')
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) then
ToolFolder[v]:Clone().Parent = backpack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild('Humanoid'):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local ToolTable = {}
for i, v in pairs(player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolFolder ~= nil then
SavedData:SetAsync(player.UserId, ToolTable)
end
end)
Im super sorry
I have to go sleep
very sorry
it's okay
Will you be here tmr?
sure but ping me or dm me if i don't answer
tsym! you're a hero
since i don't understand why it's not working we will try to understand by using print()
add a print(ToolData) after if ToolData ~= nil then
and print(ToolTable) before SavedData:SetAsync(player.UserId, ToolTable)
Im not at my computer anymore im brushing my teeth xd
as we can see if in ToolData there is your tool multiple times after saving, and when it does in your backpack, we will se if the saved table save every single tools with the same name
because we want to know where the script is not working like we want
sure you can do that tmr
Thx
np
ROBLOX Studio Tool Save Data Store Tutorial
Discord Server: https://discord.gg/sSDg29y
ROBLOX Group: https://www.roblox.com/groups/5176394/Gamer-M8-YT#!/about
Hey guys, in today's video I'm showing you how to make your own Tool Save script using Data Store!
If You Enjoyed This Video, Remember To Leave A Like, Comment And Subscribe!
This is the tutorial i followed btw
this is not a great tutorial for beginners (i guess you are for data store)
first learn about datastores
I made a datastore for the currency
and you understand ?
it's exactly the same thing lemme explain
basically you are saving a value only 1
for currencies
I used pcall in the currency
but for tools it's not the same it's an entire inventory
the difference is here : the use of for loops
when the player leaves the game
you actually get every child of his backpack and place their names in a table
if there are 3 tools : Axe Sword Pickaxe
your table could be like this : print(NameOfTable[1] ) would be "Axe" etc
and you saved that table
So I can just use the same thing i used for the currency but change the script a little?
yes
Ok tysm
I will come back tme
Tmr
Its so late
Goodnight (if you're going to sleep)
Then when the player rejoin you want, for every tools name in the table add a clone of the tool
ty you too
Ty
Ok
that's why you're doing for i, v in pairs(ToolData where v is the tool name
and clone the child named v in your toolfolder (ToolFolder[v]) to clone it in the backpack/StarterGear
i hope you understand more about the script now
try making your own
and ask help here if your stuck
I will thank you so much
So I got it to work but
It only saves the backpack
But when I do humanoid:UnequipTools()
It still doesn't save the item in the hand
@olive ridge
local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("Stats")
local toolsFolder = game.ReplicatedStorage.Tools
game.Players.PlayerAdded:Connect(function(plr)
local savedItems = data:GetAsync(plr.UserId.."-Items")
if savedItems then
for i, item in pairs(savedItems) do
for i, tool in pairs(toolsFolder:GetChildren()) do
if item == tool.Name then
local toolClone1 = tool:Clone()
toolClone1.Parent = plr.Backpack
local toolClone2 = tool:Clone()
toolClone2.Parent = plr.StarterGear
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
plr.CharacterRemoving:Connect(function(char)
local humanoid = char.Humanoid
humanoid:UnequipTools()
end)
local suc, err = pcall(function()
local savedItems = {}
for i, item in pairs(plr.Backpack:GetChildren()) do
table.insert(savedItems, item.Name)
end
data:SetAsync(plr.UserId.."-Items", savedItems)
end)
end)
new script
@olive ridge idk why it doesn't save the item in the player's hand
Even though I put "humanoid:UnequipTools()"
try removing the function
and let " local humanoid = char.Humanoid
humanoid:UnequipTools() " alone
** You are now Level 5! **
yes sorry
define char then
local char = plr.Character
or just
local humanoid = plr.Character.Humanoid
wtf
bruh
do you know why it is not working ?
why
could you sned your knew script?
local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("Inventory")
local toolsFolder = game.ReplicatedStorage.Tools
game.Players.PlayerAdded:Connect(function(plr)
local savedItems = data:GetAsync(plr.UserId.."-Items")
if savedItems then
for i, item in pairs(savedItems) do
for i, tool in pairs(toolsFolder:GetChildren()) do
if item == tool.Name then
local toolClone1 = tool:Clone()
toolClone1.Parent = plr.Backpack
local toolClone2 = tool:Clone()
toolClone2.Parent = plr.StarterGear
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local char = plr.Character
local humanoid = char.Humanoid
humanoid:UnequipTools()
local suc, err = pcall(function()
local savedItems = {}
for i, item in pairs(plr.Backpack:GetChildren()) do
table.insert(savedItems, item.Name)
end
data:SetAsync(plr.UserId.."-Items", savedItems)
end)
end)
@olive ridge
this is the new script
wait
removing the function just made the script not work
you there?
re
you're french ?
yes?