local Accessories = {}
for Index, Instance in next, Model:GetChildren() do
if Instance:IsA("Accoutrement") then
local CopiedInstance = Instance:Clone() --[[ so we wont get issues that related to "being worn by another character"
and we can call in to destroy the previous instance without having the "property is
locked" issue --]]
Instance:Destroy()
table.insert(Accessories, CopiedInstance)
end
end
I know the way I call my variables is pretty strangeābut would this code cause any future potential issues before I call it complete?
What this code does is put all of the accessories in the character into the table. So, when we want to attach these accessories into the character again after the player modelās character is rebuilt, we can run this without issues:
for Index, Accessory in next, Accessories do
Humanoid:AddAccessory(Accessory)
end
Why not just store the originals, then readd them back when needed?
As for whether any problems will arise, Iām not too sure, but youāll constantly have to destroy the originals, then add new ones to the player every time.
1 Like
I think the biggest issue is that you are overwriting the Instance global for that scope, which should be avoided.
That will cause several issues, such as āProperty Lockedā issue, and a slight issue of āSome Character is already wearing that itemā
Thatās why I clone them
What happens if I do that?
I donāt have any issues when I run the script with the āInstanceā being the variable for that loop
It wonāt be a āproblemā unless you need to use Instance.new.
But itās a bad practice and frowned upon in programming circles because it makes your code hard to edit or understand later on.
Iāve used Instance.new several times in my script after that code runs and there was no issues in a result.
However, yeah sure Iāll consider changing it for understanding the code alot better
The variable is only changed inside of the loop, it wonāt affect anything after it.
Sums up why I magically put āInstanceā as the variable