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

UnequipTools is not a valid member of Tool?

Asked by 6 years ago

Hi, I'm trying to make it so my script first unequips any tools they have open, then destroys them. I'd really like to make this work as having them NOT unequip first causes glitches with some animations and effects and what not for my games.

                        for _,v in pairs(p.Backpack:GetChildren()) do
                            if v:IsA'Tool' or v:IsA'HopperBin' then
                                v:UnequipTools()
                                v:Destroy()
                            end 

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

the UnequipTools() function is used with the player's humanoid so lets do this

First let's use that function on the humanoid

local p = player --change this

p.Character.Humanoid:UnequipTools()

Now let's remove all the player's tools in their backpack

local p = player --change this

p.Character.Humanoid:UnequipTools()

for _,v in pairs(p.Backpack:GetChildren()) do
    if v:IsA("Tool") then
        v:Destroy()
    end
end

We check that what we are destroying is a tool

Extra comments example:

local p = player --change this

for _,v in pairs(p.Character:GetChildren()) do
    if v:IsA("Tool") then
        v.Parent=p.Backpack
    end
end
for _,v in pairs(p.Backpack:GetChildren()) do
    if v:IsA("Tool") then
        v:Destroy()
    end
end
0
Is there supposed to be more to this? Seems like it's cut off. What is local p = player supposed to be? ?__? LuckyAura -1 — 6y
0
@LuckyAura I said 'change this' right after it, change it to the player who u want this to happen to, also no thats all DanzLua 2879 — 6y
0
Alright, what would it be if I want it to happen to anyone? LuckyAura -1 — 6y
0
I don't know in which way you will be implementing the script I gave you. You'd want to do this on the server side though if FE is on DanzLua 2879 — 6y
View all comments (17 more)
0
@LuckyAura DanzLua 2879 — 6y
0
Oh, FE isn't on LuckyAura -1 — 6y
0
Then the script will work in both a localscript and regular script. But I recommend learning about FE DanzLua 2879 — 6y
0
Everything you do should be fe compatible DanzLua 2879 — 6y
0
I know that but what would player be changed to if I want it to be for anyone LuckyAura -1 — 6y
0
I don't know what you are using this for thats the problem, a random person chosen? everyone at the same time? DanzLua 2879 — 6y
0
it's part of a cloned GUI, so for the person that has their own copy of it open. LuckyAura -1 — 6y
0
then assuming FE is off we can change it to local p = game.Players.LocalPlayer if its in a localscript DanzLua 2879 — 6y
0
Not sure if it's cause in Studio, but instead of Unequipping and removing it, it just keeps it equipped and doesn't remove it. LuckyAura -1 — 6y
0
If I deselect said tool myself, then when the script runs again, it just keeps the tool tool I had equipped but removes the others. LuckyAura -1 — 6y
0
where is the script located DanzLua 2879 — 6y
0
it is located inside of a Frame, that is in a ScreenGUI, inside of the StarterGUI. It's not removing unequipping the selected tool or even removing all of the other tools that were in the Backpack. :-( LuckyAura -1 — 6y
0
if the UnequipTools function isn't working then you can replace it by going through all of the children of the character and if it's a tool move it to the backpack DanzLua 2879 — 6y
0
Wouldn't it be close to this? for _,v in pairs(p.Backpack:GetChildren()) do Since the tools are moved from the backpack to the players model inside of Workspace, how would it look there as well? LuckyAura -1 — 6y
0
I edited answer^ DanzLua 2879 — 6y
0
Thank you so much for your help man, I noticed that the reason it wasn't removing some things is because a few tools that I have are HopperBins, and I wasn't including it to remove those as well. Doh'! LuckyAura -1 — 6y
0
;p accept answer :3 DanzLua 2879 — 6y
Ad

Answer this question