I’m trying to use getchildren() to destroy() the players holstered weapons, how would I destroy just these models inside the character using the holstered word as prefix?

local NameToFind = "holstered"
for i, v in pairs(pathtoplayerweapons) do
if v.Name:sub(1,NameToFind:len()) == NameToFind then
v:Destroy()
end
end
Could you help me out with getting the descendants, they’re just children inside the players character
Replace the :GetChildren() in your for loop with :GetDescendants()
I’ve been using GetDescendants but how would I replace pairs(pathtoplayerweapons) with it
Here’s a function to destroy a single weapon names holster on its equip, maybe the path could help
local holsteredWeapon = character:FindFirstChild("holstered_weapon_"..properties.storageName)
if holsteredWeapon then
holsteredWeapon:Destroy()
end
if (holsteredWeapon) then
for _, part in pairs(holsteredWeapon:GetDescendants()) do
end;
end;
This?
just this part
character:FindFirstChild("holstered_weapon_"
The path to get the named models for the loop
What is “properties.storageName“ and what does the output read?
storageName is a name value inside of the tools module, its used for ui and things that require the gun name, but all I’m trying to do here is delete the holstered weapons inside the character, by doing so it would be easiest to read for the models that start with the name holstered, and then destroy them.
Omg lol if it’s the name of a value then you have to do properties.storageName.Value lol
Now it should be:
local holsteredWeapon = character:FindFirstChild("holstered_weapon_"..properties.storageName.Value)
if (holsteredWeapon) then
for _, part in pairs(holsteredWeapon:GetDescendants()) do
end;
end;
This?
No, I’m trying to get all the models inside of a character that start with the word holstered, no weapon names.
@TenBlocke Literally gave you a valid solution, just put in character:GetDescendants() instead of pathtoplayerweapons. Well and obviously define who the character, by setting the variable.
Is this on a serverscript? you can only use .LocalPlayer in localscripts
I fixed it, I had to put it local character in my function
for _, instance in ipairs(folder) do
if instance.Name:find("^holstered") then
instance:Destroy()
end
end
Your solution was a little long-winded.

