Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

Don't use while wait() do and your code needs restructuring. You also never defined Effects anywhere.

0

Oh I forgot- I added the effects table now

1 answer

✓ Accepted answer

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)

2 comments

0

nice syntax error on line 3 of your second script

0

thanks i free-handed it

This discussion is preserved as it was. New answers, comments, and votes are closed.