Backpack:GetChildren confusion

I am trying to create a function that will clear the players inventory although the item is not removed from the players inventory and is still usable, however after running the function the item loses its default grip and is glitched


(Above is default before dropped, as it should remain)

image
(Above is after the function is ran and the item is dropped, glitched and following the players arms movement)

This is the code I am trying to use, I tried looking at ways to do this and this is the result

function loadToolsRequest.OnServerInvoke(player)
	
	for i, toolInBackpack in pairs(player.Backpack:GetChildren()) do
		toolInBackpack:Destroy()
		wait()
	end

end

This destroys the tools unequipped, in other words if the player equips a tool and this function runs, it will not be removed.

local tool = player.Character:FindFirstChildOfClass("Tool")
if tool then
    tool:Destroy()
end

remember to delete the tool from the character!!1!11!

If I remember correctly, when a tool is equipped, it is parented to the character.
To remove an item you could either de-equip before destroying or looping through the character to delete the tools.

Thanks for the reply, I tried using your code however it still seems to occur

Basically what happens in the background is;
The player loads a save slot containing a tool → The player loads a different save slot with no tool stored in it causing the function to run → The original tool remains in the players inventory and becomes glitched, notably seen when attempted to drop

Thanks for the reply, I tried using this snippet within the function earlier however it still occurred, perhaps this is some sort of bug?

local GetTools = player.Backpack:GetChildren()
local HeldTools = player.Character:GetChildren()

if GetTools then
	for i,v in pairs(GetTools) do
		v:Destroy()
	end
end

for i,v in pairs(HeldTools) do
	if v:IsA("Tool") then
		v:Destroy()
	end
end

how is the model made? are you using motors? or anything irregular from normal tools?

Is the tool still in the explorer after destroying it?

The model is generic parts which was converted to a tool using tool grip editor as well as others. From what I can see it is currently generic parts and welds.

This confuses me as it seemed to work earlier except it stopped working randomly.

From what I can see retrying the snippet, it is still in the players backpack

Upon further testing I can see that there seems to be some sort of visual bug once the glitched tool is dropped as it is not displayed in the servers view, should I forward this to the bugs category?

Ok, try that out:

local GetTools = player.Backpack:GetChildren()

player.Character.Humanoid:UnequipTools()

if GetTools then
	for i,v in pairs(GetTools) do
		v:Destroy()
	end
end

If this doesn’t work I don’t know what it could be.

Hmm It still seems to occur, I’ll forward this off to the bugs category but thank you @nontoxicguy1 and @iotalua for your effort!

do you weld the tool to the character?

I assume it is welded correctly as it works normally before the function is ran, since the bug reports create button is greyed out I am in the process of emailing roblox instead, but thanks again for the effort!

Wait that means you weld it? Tools are already attached to the character so no need to do that.

There are welds within the model which I assume is as a result of the tool grip plugin or another aspect of the video I followed.

Upon further testing I can see that there seems to be some sort of visual bug once the glitched tool is dropped as it is not displayed in the servers view.

Maybe the problem is that plugin. First what does it do? without a plugin roblox automatically attachs the tool to the character. Second, try making what you’re trying to do without this plugin.

Contact @Bug-Support instead, emailing roblox isn’t a good idea, as timezones exist, if you didn’t get a response, bump the topic, if you never got it, then bump the topic constantly

Why not do:

player.Backpack:ClearAllChildren()

And I don’t see the use of adding a wait in a for loop.

I didn’t realize this was a thing, thanks!