Looping remote event?

So I have this remote event but its looping, any help?

local re = Instance.new("RemoteEvent",game.ReplicatedStorage)
re.Name = "RemoveBal"

re.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local humanoid = Character.Humanoid
local accessories = humanoid:GetAccessories()
game.ReplicatedStorage.RemoveBalClient:FireClient(Player)
			wait(1)
	for _,accessory in pairs(accessories)do
			for _,child in pairs(accessory:GetChildren())do
				if child.Transparency then
					child.Transparency = 0
Character.MaskForHide:Destroy()
local dog = Character.BlackMask or Player.Backpack.BlackMask
dog.Handle.Transparency = 0
				end
			end
	end
	end)
1 Like

What do you mean by looping? Do you mean its creating multiple? Could you provide what is firing re to make this loop?
I also cleaned your code to make it easier to read;

local re = Instance.new("RemoteEvent",game.ReplicatedStorage)
re.Name = "RemoveBal"

re.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local humanoid = Character.Humanoid
local accessories = humanoid:GetAccessories()
game.ReplicatedStorage.RemoveBalClient:FireClient(Player)
wait(1)
for _,accessory in pairs(accessories)do
  for _,child in pairs(accessory:GetChildren())do
    if child.Transparency then
      child.Transparency = 0
      Character.MaskForHide:Destroy()
      local dog = Character.BlackMask or Player.Backpack.BlackMask
      dog.Handle.Transparency = 0
    end
  end
end
end)
2 Likes

image

1 Like

Your issue is MarkForHide isn’t a valid member of the Character, so I recommend you add an if statement to see if MarkForHide exists before you try destroying it.

2 Likes

It is tho? It deletes it, but the script for some reason is sstill looking

1 Like

Adding the if statement will make the script stop looking, because if MaskForHide no longer exists, that area of the script doesn’t run.

If you want to make it stop looking after the mask has been destroyed you might want to add a break or return depending on your use case.

local re = Instance.new("RemoteEvent",game.ReplicatedStorage)
re.Name = "RemoveBal"

re.OnServerEvent:Connect(function(Player)
	local Character = Player.Character
	local humanoid = Character.Humanoid
	local accessories = humanoid:GetAccessories()
	
	game.ReplicatedStorage.RemoveBalClient:FireClient(Player)
	wait(1)
	
	for _,accessory in pairs(accessories)do
		for _,child in pairs(accessory:GetChildren())do
			if child.Transparency then
				child.Transparency = 0
				
				local Mask = Character:FindFirstChild("MaskForHide")
				if Mask then
					 Mask:Destroy()
				end
				
				local dog = Character.BlackMask or Player.Backpack.BlackMask
				dog.Handle.Transparency = 0
				return --or break
			end
		end
	end
end)
1 Like