Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

className == "Tool" Not working??

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()	

4 comments

0

Do you call this function at any given moment trough the local script ?

0

yeah, forgot to add that above, still can't figure it out..:/

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.

0

Figured it out, just needed to add a simple loop. thanks guys

2 answers

: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()   

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()

This discussion is preserved as it was. New answers, comments, and votes are closed.