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

className == "Tool" Not working??

Asked by
NotPix 2
7 years ago
Edited 7 years 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 483 — 7y
0
yeah, forgot to add that above, still can't figure it out..:/ NotPix 2 — 7y
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 4988 — 7y
0
Figured it out, just needed to add a simple loop. thanks guys NotPix 2 — 7y

2 answers

Log in to vote
0
Answered by 7 years 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 years 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