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)
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)
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.
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)