So im making a game with Swords, and i want them Displayed on the back of the Player, before they are equipped. Now for that i was Planning on using a small script which searches for back Accessories and removes them. Now in my case, im thinking that code should work perfectly fine, but it isn’t removing anything (no errors etc)? Am i missing something or could the script as itself not work ( Script is in starter character scripts)
local character = script.Parent
for i, child in pairs(character:GetChildren()) do
if child:IsA("Accessory") then
warn("Found: "..child.Name, i)
if child.AccessoryType == Enum.AccessoryType.Back then
child:Destroy()
warn("Removed: "..child.Name,i)
else return end
end
end
local character = script.Parent
for i, child in pairs(character:GetChildren()) do
if child:IsA("Accessory") then
warn("Found: "..child.Name, i)
if child.AccessoryType == Enum.AccessoryType.Back then
child:Destroy()
warn("Removed: "..child.Name,i)
end
end
end
local character = script.Parent
for i, child in pairs(character:GetChildren()) do
if child:IsA("Accessory") and child.AccessoryType == Enum.AccessoryType.Back then
child:Destroy()
warn("Removed: "..child.Name)
end
end
I think the issue is that the character hasn’t completely loaded when the script executes.
Try this:
local Players = game:GetService("Players")
local character = script.Parent
local player = Players:GetPlayerFromCharacter(character)
player.CharacterAppearanceLoaded:Wait()
for i, child in pairs(character:GetChildren()) do
if child:IsA("Accessory") and child.AccessoryType == Enum.AccessoryType.Back then
child:Destroy()
warn("Removed: "..child.Name)
end
end
This code waits for the character’s appearance to load before executing the for loop.
OH Thank you for your answer, i have not thought of that yet. Uppon reading that i realized i overthought a little. The minor things can cause Huge things. Thanks for your helpful reply