Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What did I do wrong here with this simple Accessory Effect Remover Script?

Asked by 5 years ago
Edited 5 years ago

This is supposed to sort through the accessories in a player's character and destroy any effects. It's not destroying the effects though.

Effects = {"Fire","Smoke","Sparkles","PointLight","SpotLight"} 
workspace.ChildAdded:Connect(function()
for i, accessory in next, workspace:GetDescendants() do
if accessory:IsA('Accessory') then 
    for i, effect in pairs(accessory:GetChildren()) do
for num = 1, #Effects do
    if effect:IsA(Effects[num]) then
    effect:Destroy()    
end end end end end end)

0
Don't use while wait() do and your code needs restructuring. You also never defined Effects anywhere. User#24403 69 — 5y
0
Oh I forgot- I added the effects table now ShadyShock 77 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited by User#24403 5 years ago

your issue is that you're searching through the Accessory object, and not the BasePart that the effect would be in.

local Effects = {
Fire = true,
Smoke = true,
Sparkles = true,
PointLight = true,
SpotLight = true
} --i just added this change so you wouldn't iterate through a list every time you wanted to check for a single object. idk if it's more efficient, but comes off a bit more elegant imo
for i, v in pairs(accessory.Handle:GetChildren()) do
    if Effects[v.ClassName] then
        v:Destroy()
    end
end

also i'm unclear about if ChildAdded works on children of the added Child (so in this case, a character is added, i'm not sure if it works on the Accessories inside the character.), so you might want to connect this to something like ...

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        for i,v in pairs(char:GetChildren()) do -- fixed xd
            if v:IsA("Accessory") then
                --etc
                --etc
                --etc
            end
        end
    end)
end)
0
nice syntax error on line 3 of your second script DeceptiveCaster 3761 — 5y
0
thanks i free-handed it kaboom680 63 — 5y
Ad

Answer this question