Tool is nil, when it is being defined

My tool is nil when it is being defined, I have no idea why this is being caused.
When the tool is being defined in the isEquipped if statement, it is nil when I try to destroy it.
Help is appreciated alot!

This could have something to do with the fact that it’s in an ‘else’ statement, as this could be running without the tool being equipped.

What am I supposed to do then? I’m really confused

Is it tied to an equipped function?

What I’d do regardless is check if Tool isn’t nil, then run the Destroy() function.
I also see a commented else-if below your else, which checks for the Tool.

Yeah, I did comment the else if statement, since it wouldn’t run, and it would just duplicate the tool in my inventory, the tool does parent to the backpack, but when i try to destroy it, its nil.

Also, its not tied to an equipped function its tied to an MouseButton1Click

You could try:

elseif not isEquipped and Tool and Frame.BackgroundColor3 == Color3.fromRGB(85, 255, 0) then

I just tried this, The tool is still nil, but it does print the destroyed print statement. image

Show me the whole script, So I can help you

The parent is nil. But i’m confused on how it is nil, since it is being parented to the backpack.

Server:


Client: image

Try using another variable for the tool, or print the tool itself for further reference.

You have to define the Tool variable outside of the event. Otherwise, the Tool will be defined again, making it’s parent nil - because it’s a new clone.

1 Like

How would that help though, I did print tool, its the name of the tool, so I know the tool is being cloned, and IT is being parented to the backpack. But its nil after the elseif, and i’m still confused on why

Can u try setting the parent of tool outside the if statement?

1 Like

Your reply fixed my error, but the next time i try to click on the ui, the object is nil since the clone is destroyed, how would I get a new clone?

In the CloneEvent, check if the clone is nil before doing the main if statement. If it is, create a new clone and set the value of the Tool variable to the new clone. This should work.