I have this game, that’s WIP.
In this game, you pick a class and fight, script automatically equips you with armor and weapon meant for that very class. However, there’s this pesky bug, that i have no idea how to get rid of. What’s happening, is that i have a certain line of code that checks if the accessory contains the said script inside it (armor pieces and things are contained inside accessory instance), if script is missing, it deletes the accessory.
Here’s the code (For clarification, script looks for accesory in character of the player it’s parented to, “wearable” is any accessory inside character and “flag” is the script itself):
if not wearable:FindFirstChild(flag) then
wearable:Destroy()
end
And the result?
As you can clearly see, bandana and medal is still there (there was a hat too, but that was successfully deleted by the script.
Any help as to how fix this bug would be appreciated.
Edit: You might also be removing accessories before the character’s appearance loads, so only some of the accessories are created before you destroy them.
Replying way late (mainly because only now, do i have time and motivation) but this changes nothing, for some reason it doesen’t seem to detect the previously mentioned accessories.
Edit: The weirdest thing is, when i run a print command, it only outputs the hat’s name.
I am assuming that the LocalScript is in the Character model so when it runs, the character has not fully loaded itself, leaving the script thinking that the accessories aren’t there.
Maybe try adding the yield function before the loop runs.
Example:
local Player = game["Players"]["LocalPlayer"]
local Character = Player["Character"] or Player["CharacterAdded"]:Wait()
wait(2)
for Int, Wearable in pairs(Character:GetChildren()) do
if not Wearable:IsA("Accoutrement") then
continue
end
Wearable:Destroy()
end
Edit: Wait so the LocalScript knows the accessories are there but aren’t destroying them?
Can you post the output you got when you ran the print command?
Seems i need to explain a thing or two:
So the script itself is contained inside the armor, which is held in ReplicatedStorage until player clicks a button, which then clones the armor, once script sees that it’s parent is a parent of a player in question, it attaches itself to their character and deletes their accessories, so that accessories player wears don’t overlap with the armor.
Also, it’s a ServerScript, because i want other players to see the armor player is wearing too.
Here’s the output:
(that’s the only accessory it detects)
local Players = game:GetService("Players")
local Armor = script["Parent"]:Clone()
Players["PlayerAdded"]:Connect(function(Player)
Player["CharacterAppearanceLoaded"]:Connect(function(Character)
for Int, Wearable in pairs(Character:GetChildren()) do
if not Wearable:IsA("Accoutrement") then
continue
end
Wearable:Destroy()
Armor["Parent"] = Character
end
end)
end)
This should do the exact thing as:
But in a ServerScript.
Edit: BTW, if the script is just looking for accessories and destroying them and cloning the armor afterward, then after cloning the armor, you should disable or maybe even destroy the cloned script inside the cloned armor itself.
Snippet:
Armor["Parent"] = Character
end
Armor["Script"]:Destroy()
No, the script creates constraints for armor pieces first, then it does the accessory removal and lastly, there’s a failsafe which checks whether the player had successfully equipped armor, if not, it kills them.
By the way, i should point out, that the way armor is constructed and attached, does not require a child called “Handle”.
Edit: After some investigations, i concluded that your solution as it stands, doesen’t work, however i had tried to implement a loop before, but the problem is, it removes the armor too, for some odd reason that’s beyond me.