Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Equipped is not a valid member of Part? Works for another tool

Asked by
painzx3 43
1 year ago

Making a tool that is supposed to spawn a clone of the tool in hand on M1. Works on other tool, but not with the one I put the LocalScript in.

For context, the LocalScript is in the tool 'Handle' and has a RemoteEvent that has a script descendent.

On test, the following error pops up: Equipped is not a valid member of Part "Players.[PlayerName].Backpack.[ModelName].Handle"

Interestingly enough, this LocalScript (and all it's descendents) functions properly on the original tool it was in and I've double checked to see if I've missed any parts in the tool that are maybe critical and found none apart from a Handle (which is already in the tool I'm trying to debug)

Below is the LocalScript in question, any help would be appreciated:

bin = script.Parent

function onSelected(mouse)
    mouse.Button1Down:connect(function()
        script.RemoteEvent:FireServer(mouse.hit.p)
        script.Parent:Destroy()
    end)
end



bin.Equipped:connect(onSelected)
1
Place the script under the tool, not the handle. T3_MasterGamer 2189 — 1y
1
Tools have the .Equipped event, while parts do not. T3_MasterGamer 2189 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

When you are referring to bin, you are referring to a part of the tool. ** Check the location of the local script. **As you can see by the error, you are referring to a part of the tool (the handle), not the tool itself.

I have two fixes.

1. Move the localscript so it is directly under the tool or you can change the variable.

or

2. Replace the script

Instead of

bin = script.Parent

do

bin = script.Parent.Parent

Because if you do the first one, you are merely referring to a part. The second one is referring to the tool. Here is the full script:

bin = script.Parent.Parent

function onSelected(mouse)
    mouse.Button1Down:connect(function()
        script.RemoteEvent:FireServer(mouse.hit.p)
        script.Parent:Destroy()
    end)
end



bin.Equipped:connect(onSelected)

But why does this error occur in the first place?

The handle is merely a part, it does not contain the .equipped event. You are trying to connect the .equipped event to a function via the handle but the handle does not have that property. Instead use the tool. The tool contains the .equipped event.

Ad

Answer this question