#This script is working but

129 messages · Page 1 of 1 (latest)

fleet wave
#

if you don't understand, tell me what you don't understand and I'll explain it

#

If you don't underrstand my thing, I will do my best to reiterate

olive ridge
#
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

fleet wave
#

how do I fix it

olive ridge
#

maybe remove and backpack:FindFirstChild(v) == nil

#

it may work

fleet wave
#

ok

#

nop

#

e

#

it didn't

#

it just did the same thing it did before

olive ridge
#

remove this ``and StarterGear:FindFirstChild(v) == nil`

#

i forgot to tell you abt this but removing it should work

fleet wave
#

ima go try

olive ridge
#

i think you should learn a bit more about coding before actually follow a tutorial

#

i guess you want to make a game

fleet wave
#

yes

#

Ugh

#

still doesnt work

olive ridge
#

if you don't understand everything you will have a lot of problems

#

as this one

fleet wave
#

ye 😅

olive ridge
#

send your script again

#

but while sending it

#

put it like this :

fleet wave
#
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

olive ridge
#

it's okay

fleet wave
#

Will you be here tmr?

olive ridge
#

sure but ping me or dm me if i don't answer

fleet wave
#

tsym! you're a hero

olive ridge
#

add a print(ToolData) after if ToolData ~= nil then

#

and print(ToolTable) before SavedData:SetAsync(player.UserId, ToolTable)

fleet wave
#

Im not at my computer anymore im brushing my teeth xd

olive ridge
#

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

olive ridge
fleet wave
#

Thx

olive ridge
#

np

fleet wave
#

This is the tutorial i followed btw

olive ridge
#

first learn about datastores

fleet wave
#

I made a datastore for the currency

olive ridge
#

and you understand ?

fleet wave
#

Wht I did yes

#

What he did no

olive ridge
#

it's exactly the same thing lemme explain

#

basically you are saving a value only 1

#

for currencies

fleet wave
#

I used pcall in the currency

olive ridge
#

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

fleet wave
#

So I can just use the same thing i used for the currency but change the script a little?

olive ridge
#

yes

fleet wave
#

Ok tysm

#

I will come back tme

#

Tmr

#

Its so late

#

Goodnight (if you're going to sleep)

olive ridge
#

Then when the player rejoin you want, for every tools name in the table add a clone of the tool

olive ridge
fleet wave
#

Ty

olive ridge
#

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

fleet wave
#

I will thank you so much

fleet wave
#

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()"

olive ridge
#

and let " local humanoid = char.Humanoid
humanoid:UnequipTools() " alone

fleet wave
#

char doesn't have a variable

#

@olive ridge you there?

real arrowBOT
#

studio** You are now Level 5! **studio

olive ridge
#

yes sorry

olive ridge
#

local char = plr.Character

#

or just

#

local humanoid = plr.Character.Humanoid

fleet wave
#

oh

#

it does't work

#

@olive ridge

#

it still doesn't work

#

this guy is reacting

olive ridge
#

wtf

fleet wave
#

bruh

olive ridge
#

do you know why it is not working ?

fleet wave
#

no

#

well i know why it isn't working

olive ridge
#

why

fleet wave
#

because it doesn't unequi^p

#

but how do I unequi^it

olive ridge
#

could you sned your knew script?

fleet wave
#
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?

olive ridge
#

re

fleet wave
#

slt

#

hello*

olive ridge
#

you're french ?

fleet wave
#

yes?

olive ridge
#

do you think we can speak french

#

dm me