#My script is not working altho has no errors in output.

287 messages · Page 1 of 1 (latest)

tawny bear
#

i tried it it does not print for some reason

full daggerBOT
#

studio** You are now Level 4! **studio

tawny bear
#

no errors in output.

pale saffron
full daggerBOT
#

studio** You are now Level 3! **studio

tawny bear
#

it does not print anywhere

pale saffron
#

Oh okay.

#

Try add a print add the beginning of the .Removing event just to make sure that works

tawny bear
#

k

#

1 min

pale saffron
#

otherwise it's probably because your "Folder:FindFirstChild(name)" isn't true

#

if Folder:FindFirstChild(name) then

pale saffron
#

yeah try that

tawny bear
#

i put it in the first line

pale saffron
#

Mhm

#

can you send screenshot of the script?

#

You sure there's no errors? this line seems weird: for i, name in inventory do

tawny bear
pale saffron
#

yeah well you would use in pairs(inventory)

tawny bear
#

it printed

pale saffron
#

screenshot code

tawny bear
#

i did but it failed

pale saffron
#

Hm wdym?

#

can't you screenshot

tawny bear
pale saffron
#

Okay so first of there's a visible error

#

lowercase the "I" on whatever line that is

tawny bear
#

oh ill change that

full daggerBOT
#

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

pale saffron
#

because the "item" property isn't with a uppercase I

#

yeah

#

If you got one of those red marks it means your script has a clear error that needs to be fixed

tawny bear
#

still didn't print

#

or do its assigned thing

pale saffron
#

okay it didn't print the first line?

tawny bear
#

but when i leave it does not save anything

#

Or when i join it does not do anything

pale saffron
#

Okay, but it does detect you've left?

tawny bear
#

Event

pale saffron
#

alr

#

And are there even any objects in the BP?

tawny bear
pale saffron
#

yeah

#

are there any tools there to be saved

#

when you test

tawny bear
#

yes

pale saffron
#

Okay.

tawny bear
#

i use a tool

pale saffron
#

Change the pairs to "ipairs"

tawny bear
#

nope same

pale saffron
#

No output except the first print ?

#

no errors?

tawny bear
#

yes

pale saffron
#

try print BP:GetChildren() and show me

tawny bear
#

k

#

no prints

pale saffron
#

huh

tawny bear
#

i don't think u can print objects

tawny bear
pale saffron
#

try this

#

game:GetService("Players").PlayerRemoving:Connect(function(Player)
print("Player:", Player, "has discoonected.")
print(Player.Backpack:GetChildren())

local char = Player.Character or Player.CharacterAdded:Wait()
local Items = {}

for _, Object in ipairs(Player.Backpack:GetChildren()) do
    print(Object)
    
    if Object then
        print("Object is a tool!")
        table.insert(Items,Object.Name)
        print("saved",Object,"for",Player)
    end
    
end

MainData:SetAsync(Player.UserId,Items)

end)

pale saffron
#

replace the removingevent

tawny bear
#

TEACH ME

pale saffron
#

with what I sent

#

and show me the prints

tawny bear
#

ok i did

pale saffron
#

wait I had 1 error in the script wait

#

can you show it all?

#

expand the table as well

tawny bear
#

k

pale saffron
#

game:GetService("Players").PlayerRemoving:Connect(function(Player)
print("Player:", Player, "has discoonected.")
print(Player.Backpack:GetChildren())

local char = Player.Character or Player.CharacterAdded:Wait()
local Items = {}

for _, Object in ipairs(Player.Backpack:GetChildren()) do
    print(Object)
    
    if Object:IsA("Tool") then
        print("Object is a tool!")
        table.insert(Items,Object.Name)
        print("saved",Object,"for",Player)
    end
end

print(#Items)

MainData:SetAsync(Player.UserId,Items)

end)

#

replace with that

#

screenshot the whole output

tawny bear
#

table is empty

#

altho i had smth

#

in my backpack

pale saffron
#

Hm that's strange

#

Is this a serverscript?

tawny bear
#

yes

pale saffron
#

ok, and how is the tool added?

#

to the backpack

tawny bear
#

by picking it up

pale saffron
#

Is it a server script giving you the tool?

#

or a localscript

tawny bear
#

its a normal pickable tool

pale saffron
#

oh ok.

tawny bear
#

do i make a script for it to be picked up?

#

using a server script

pale saffron
#

No shouldn't be needed

full daggerBOT
#

studio** You are now Level 4! **studio

tawny bear
#

oh

pale saffron
#

If you check in the explorer while in-game

#

wait

#

1 thing

#

When you discoonect from the game

#

Is the tool equipped in your hand?

tawny bear
pale saffron
#

So it's in the roblox backpack hotbar

#

as a tool

tawny bear
#

i sometimes equip it and leave

pale saffron
#

Ok, try unequip and then leave

tawny bear
#

k]

pale saffron
#

then look at the output

tawny bear
#

same

pale saffron
#

Nothing?

tawny bear
#

yep same

pale saffron
#

Ok, try check inside the property table if the item is there

tawny bear
#

k

pale saffron
#

first from a local view then from a server view

#

2 sec let me show u

tawny bear
pale saffron
tawny bear
# pale saffron

from client view its in the backpack and the same for server view

pale saffron
#

And there's a tool inside there?

tawny bear
#

yes

pale saffron
#

try print the players backpack randomly while in-game

tawny bear
#

objects can't be printed tho

pale saffron
#

like after 20 secs just a simple print

#

they can

tawny bear
#

how?

pale saffron
#

?

#

Just

tawny bear
#

Print(backpack)?

pale saffron
#

print(Workspace.Part)

#

no

tawny bear
#

k

pale saffron
#

that would only print "backpack"

#

print backpack:getchildren()

tawny bear
#

it does not print its children

pale saffron
#

bc you don't do Backpack:GetChildren()

tawny bear
pale saffron
#

would print a table, also why is it local?

tawny bear
pale saffron
#

it's printed from the client

#

a local script

#

printing something with :GetChildren() should always print a table idk what have happened

tawny bear
#

oh k ill try

#

same thing from server

pale saffron
#

god damn

#

that's super strange

tawny bear
#

sorry i caused u alot of trouble

pale saffron
#

tried the script myself, worked fine

#

nah it's fine

tawny bear
#

send urs if u don't mind

pale saffron
#

Try go to the server, add a tool property and then leave

#

I'm using your script, the part I sent to you

#

it works

tawny bear
#

u have the folder?

#

in Server storage

pale saffron
#

try:

game:GetService("Players").PlayerRemoving:Connect(function(Player)
print("Player:", Player, "has discoonected.")
print(Player.Backpack:GetChildren())

local Items = {}

for _, Object in ipairs(Player.Backpack:GetChildren()) do
    print(Object)
    
    if Object:IsA("Tool") then
        print("Object is a tool!")
        table.insert(Items,Object.Name)
        print("saved",Object,"for",Player)
    end
end

print(#Items)

MainData:SetAsync(Player.UserId,Items)

end)

#

see prints, with tool

tawny bear
#

do i try chat gpt troubleshoot ?

pale saffron
#

no

tawny bear
#

k

pale saffron
#

try what I sent u

tawny bear
#

k

#

IT PRINTED

full daggerBOT
#

studio** You are now Level 6! **studio

tawny bear
#

OBJECT IS A TOOL

pale saffron
#

yess

#

nice

tawny bear
#

AND 1

pale saffron
#

yeah

#

amount of items saved

tawny bear
#

says it gave me tho it didn't lol

#

backpack problem

#

ill fix it

tawny bear
#

TELL ME

pale saffron
#

u sure? I can do it if u want

#

just send the script

#

I removed a line

#

you had a line waiting for the character

#

however as the character already has been removed it was waiting in forever

#

idk why it was there, didn't notice it at first lol

tawny bear
#

so it was waiting

#

forever

#

for the character?

pale saffron
#

Yeah, you had smth like:

local Character = plr.character or Character.CharacterAdded:Wait()

full daggerBOT
#

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

pale saffron
#

however

#

you had already left so the character would never be found

pale saffron
#

and it would wait forever

tawny bear
#

DANG

#

THAT WAS THE PROBLEM AND I WAS TROUBLESHOOTING IT FOR 2 DAYS?

pale saffron
#

haha seriously?

tawny bear
pale saffron
#

wow

#

I didn't even notice that line at first tbh

#

Well

#

If you would like to I'll fix the other part too

pale saffron
tawny bear
#

i never thought it was the problem i thought it was a fix

#

since it printed nil for char

#

everytime

#

but wait i removed the char part

#

why did i keep the variable

#

💀

viscid drum
pale saffron
#

idk why would would ever want to use the character in that script tbh

#

1 reason could be to unequip all tools tho

tawny bear
#

that used the same as this

pale saffron
#

as tools that are equipped are inside the character, and not saved

tawny bear
#

but used char and backpack

pale saffron
#

Yeah, if the player has a tool equipped it won't be saved with this script

#

as the tool is inside the character, not the backpack when it's equipped

tawny bear
#

so what do i do?

#

i gotta use char

#

but

#

its nil when its in

#

bc plr loads faster than char

#

so it identifies as nil

#

char

viscid drum
#

what

#

show code

tawny bear
#

some guy suggested me to use repeat wait() until char

#
game:GetService("Players").PlayerRemoving:Connect(function(Player)
    print("Player:", Player, "has discoonected.")
    print(Player.Backpack:GetChildren())

    local Items = {}

    for _, Object in ipairs(Player.Backpack:GetChildren()) do
        print(Object)

        if Object:IsA("Tool") then
            print("Object is a tool!")
            table.insert(Items,Object.Name)
            print("saved",Object,"for",Player)
        end
    end

    print(#Items)

    MainData:SetAsync(Player.UserId,Items)
end)
pale saffron
#

You'll just do CharacterRemoving first then the PlayerRemoving I'd say

tawny bear
#

variable

pale saffron
#

let me cook hold on

tawny bear
tawny bear
pale saffron
#

yo

#

sorry

#

had to do smth rq

#

I'll do it now hold on

tawny bear
#

k np sry

pale saffron
#

alr

#

I think dinner is ready

#

try this

#

game:GetService("Players").PlayerAdded:Connect(function(Player)

local Items = {}

Player.CharacterRemoving:Connect(function(Character)
    local CharacterChildren = Character:GetChildren()
    
    for _, Obj in ipairs(CharacterChildren) do
        if Obj:IsA("Tool") then
            table.insert(Items, Obj.Name)
        end
    end
end)

Player.CharacterAdded:Connect(function(char)
    table.clear(Items)
end)

game:GetService("Players").PlayerRemoving:Connect(function(Player)
    print("Player:", Player, "has discoonected.")
    print(Player.Backpack:GetChildren())
    for _, Object in ipairs(Player.Backpack:GetChildren()) do
        print(Object)

        if Object:IsA("Tool") then
            print("Object is a tool!")
            table.insert(Items,Object.Name)
            print("saved",Object,"for",Player)
        end
    end

    print(#Items)


    MainData:SetAsync(Player.UserId,Items)
end)

end)

#

just switch out the playerremoving part to this

#

and try to equip 1 tool and see if it saves

tawny bear
pale saffron
#

it worked?

tawny bear
#

has alot of errors

tawny bear
pale saffron
#

Errors?

#

Send me

#

Wait let me test it

tawny bear
#

k

pale saffron
#

worked fine for me

#

this part u replace:

tawny bear
#

weird

tawny bear
pale saffron
#

Mk, send me the errors

tawny bear
pale saffron
#

you've copied the code wrong

tawny bear
#

should i keep it on Playeradded?

pale saffron
#

game:GetService("Players").PlayerAdded:Connect(function(Player)

local Items = {}

Player.CharacterRemoving:Connect(function(Character)
    local CharacterChildren = Character:GetChildren()
    
    for _, Obj in ipairs(CharacterChildren) do
        if Obj:IsA("Tool") then
            table.insert(Items, Obj.Name)
        end
    end
end)

Player.CharacterAdded:Connect(function(char)
    table.clear(Items)
end)

game:GetService("Players").PlayerRemoving:Connect(function(Player)
    print("Player:", Player, "has discoonected.")
    print(Player.Backpack:GetChildren())
    for _, Object in ipairs(Player.Backpack:GetChildren()) do
        print(Object)

        if Object:IsA("Tool") then
            print("Object is a tool!")
            table.insert(Items,Object.Name)
            print("saved",Object,"for",Player)
        end
    end

    print(#Items)


    MainData:SetAsync(Player.UserId,Items)
end)

end)

#

wait

tawny bear
#

?

pale saffron
#

idk how to copy paste it

#

so it copies right

#

I think there's some command

#

like

tawny bear
#

use ```lua

pale saffron
#

oh

tawny bear
#

`

pale saffron
#
game:GetService("Players").PlayerAdded:Connect(function(Player)

    local Items = {}

    Player.CharacterRemoving:Connect(function(Character)
        local CharacterChildren = Character:GetChildren()

        for , Obj in ipairs(CharacterChildren) do
            if Obj:IsA("Tool") then
                table.insert(Items, Obj.Name)
            end
        end
    end)

    Player.CharacterAdded:Connect(function(char)
        table.clear(Items)
    end)

    game:GetService("Players").PlayerRemoving:Connect(function(Player)
        print("Player:", Player, "has discoonected.")
        print(Player.Backpack:GetChildren())
        for , Object in ipairs(Player.Backpack:GetChildren()) do
            print(Object)

            if Object:IsA("Tool") then
                print("Object is a tool!")
                table.insert(Items,Object.Name)
                print("saved",Object,"for",Player)
            end
        end

        print(#Items)


        MainData:SetAsync(Player.UserId,Items)
    end)
end)
#

there

#

copy that

#

and replace

tawny bear
#

again tysm

#

i wish u good luck

pale saffron
#

👍

tawny bear
#

bye 🙂

pale saffron
#

bye

#

gl