Ad
Log in to vote
0

className == "Tool" Not working??

Asked by
NotPix 2
7 months ago
Edited 7 months ago

Attempting to make a passive script that removes the players weapon if selected, so far this is what i have which doesnt work. A local script that clones in the player when activated.


function getTool() for _, kid in ipairs(script.Parent:GetChildren()) do if kid.className == "Tool" then kid.Parent = game.Players.LocalPlayer.Backpack end end end getTool()
0
Do you call this function at any given moment trough the local script ? iDarkGames 218 — 7mo
0
yeah, forgot to add that above, still can't figure it out..:/ NotPix 2 — 7mo
0
Technically, it should be ClassName. But I just tested it with className and it seemed to work just fine. The problem likely lies elsewhere, perhaps in the children of script.Parent. Perci1 4816 — 7mo
0
Figured it out, just needed to add a simple loop. thanks guys NotPix 2 — 7mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

2 answers

Log in to vote
0
Answered by 7 months ago

:IsA(ClassName) basically does the same thing but supports base classes, so use that instead. So, to answer your question:

function getTool()  
    for _, kid in ipairs(script.Parent:GetChildren()) do
        if kid:IsA("Tool") then
         kid.Parent = game.Players.LocalPlayer.Backpack
        end 
    end 
end 

getTool()   
Ad
Log in to vote
0
Answered by 7 months ago

Another method is to call :UnequipTools() on the character's humanoid. Assuming the script's parent is the character, you could simply use the following.

script.Parent.Humanoid:UnequipTools()

Answer this question



Ad