Basically I want to disable particle emitters when a play presses a button, I have this code:
remoteeve.OnServerEvent:Connect(function(player, status, hide)
if player.Name == script.Parent.Parent.vals.nora.Value then
if status == 'hide' then
if hide == true then
for i, v in pairs(workspace[player.Name]:GetChildren()) do
if v:IsA("Model") then
for i, b in pairs(v:GetChildren()) do
if b:IsA("Part") then
for i, n in pairs(b:GetChildren()) do
if n:IsA("ParticleEmitter") then
if n.Name == "Shadow" then
n:Destroy()
end
end
end
end
end
end
end
end
end
end
end)
If I had:
print(n.Name)
it’ll print about 5/7 of the particle emitters, but when I add the n:Destroy() or n.Enabled = false it wont do anything. Please help
Assuming it is the player’s Character, you can use GetDescendants to directly search for any instance, whether it is a direct child or not.
local nora = script.Parent.Parent.vals.nora
remoteeve.OnServerEvent:Connect(function(player:Player, status, hide)
local Character = player.Character
if player.Name == nora.Value and status == 'hide' and hide and Character then
for _, v in pairs(Character:GetDescendants()) do
if v:IsA("ParticleEmitter") and v.Name == "Shadow" then
v:Destroy()
end
end
end
end)