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

Remove Tools [onTouch] Doesnt remove tool that you have equiped?

this script is meant to remove all your tools into lighting.... but the thing is if you have a tool on your hand like a pistol your using and you still use it when you touch the part it removes everything but the tool your using any help please?

function onTouched(hit)
local p = game.Players:FindFirstChild(hit.Parent.Name)
if p ~= nil then
local kit = p.Backpack
if kit ~= nil then
local tools = kit:GetChildren()
for i = 1,#tools do
wait(.05)
tools[i].Parent = game.Lighting
end
end
end
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

##Solution

All you basically have to do at this point is go through all the children of Character and use the :IsA() function on all objects through a for loop. The IsA() function will return true if the object is what you're comparing it to. Otherwise the function can return false and we can ignore it. We of course will want to use :IsA('Tool') to see if the object is a tool or not.


##Recommendation

Tab your code properly so people may read it easier.


##Final Script

function onTouched(hit)
    local p = game.Players:FindFirstChild(hit.Parent.Name)
    if p ~= nil then
        local kit = p.Backpack
        if kit ~= nil then
            local tools = kit:GetChildren()
            for i = 1,#tools do
                wait(.05)
                tools[i].Parent = game.Lighting
            end
        end
        for _,v in pairs(p.Character:GetChildren()) do --The for loop will go through all objects of p.Character.
            if v:IsA('Tool') then --If the object picked up by the for loop is a Tool, then the script should do something.
                v:Destroy() --Yep, remove the tool forever and never let it exist again.
            end
        end
    end
end

script.Parent.Touched:connect(onTouched)

######Hopefully this answered your question, if so hit the accept answer button. If you have any questions, feel free to comment below.

1 comment

0

Thank you for helping me out and umm for the bottom part where it says v:Destroy() i changed it to v.Parent = game.Lighting because i want it to be regenerated on touch to another part so thank you so much for the help i tested it and it worked still :)

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