local char = player.Character or player.CharacterAdded:Wait() and player.CharacterAppearanceLoaded:Wait()
local charchildren = char:GetChildren()
while wait(1) do
print(charchildren)
end
for i, v in pairs(charchildren) do
if v:IsA("Accessory") then
local accesory = v
accesory:Destroy()
end
end
I have tried looping through player to see if its even being processed, but it isnt for some reason, this is what loop look’s like
, also get this weird little error, but i searched it up and apparently it doesnt affect anything
local char = player.Character or player.CharacterAppearanceLoaded:Wait()
for i, v in char:GetDescendants() do
if v:IsA("Accessory") then
v:Destroy()
end
end
-- wait for just characterAppearanceLoaded because we need to wait for accessories to load in
local char = player.Character or player.CharacterAdded:Wait() and player.CharacterAppearanceLoaded:Wait()
local charchildren = char:GetChildren()
--infinite loop; blocks the execution of the rest of the code after it
while wait(1) do
print(charchildren)
end
-- the variable "v" is the current child of the character
-- its not good practice to assign a new variable to "v" when you can just rename "v" to "accessory"
for i, v in pairs(charchildren) do
if v:IsA("Accessory") then
local accesory = v
accesory:Destroy()
end
end
fixed version
local char = player.Character or player.CharacterAppearanceLoaded:Wait()
local charChildren = char:GetChildren()
print(charChildren)
for i, accessory in pairs(charChildren) do
if accessory:IsA("Acessory") then
accessory:Destroy()
end
end
placing it inside a loop seem to work ``` local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAppearanceLoaded:Wait()
while wait() do
for i, v in char:GetDescendants() do
if v:IsA(“Accessory”) then
v:Destroy()
end
end
Then you create another loop that is supposed to remove accessories, but it won’t be called because the “while true do” loop keeps looping and stops in one place.
I wouldn’t prefer you to use loops within loops. Just use the function:
coroutine.wrap
That is:
local char = player.Character or player.CharacterAdded:Wait() and player.CharacterAppearanceLoaded:Wait()
local charchildren = char:GetChildren()
local WhileLoop = coroutine.wrap(function()
while wait(1) do
print(charchildren)
end
end)
local DeleteAccesories = coroutine.wrap(function()
for i, v in pairs(charchildren) do
if v:IsA("Accessory") then
local accesory = v
accesory:Destroy()
end
end
end)
WhileLoop() -- Start Loop which print "charchildren"
DeleteAccesories() -- Start "For" loop which delete accesories
Using the “coroutine.wrap” function means that the script does not stop in one place and simply signs as
local FunctionName = coroutine.wrap(function()
--Code
end)
FunctionName() --Activating function
If you’re using loop, coroutine.wrap will play until you don’t break it.
Ultimately, it turns out that both loops will be launched at the same time and the script will not get stuck in place. Now everything will work simultaneously, without lags or stopping the script.
You can pin my answer so others can learn about it too.