I made this admin command where it starts a while loop to search for this specific blacklisted gear and deletes it from the player’s inventory and sends a remote event to show a notification. However, when I wrote a command to set the blacklist boolean to true or false, it does change to that boolean but the loop doesn’t start of end. Any help is appreciated.
game.Players.PlayerAdded:Connect(function(plr)
local blacklist = true
plr.Chatted:Connect(function(msg)
if plr.Name == 'konoxide' then
if msg == 'k/blacklist'..' '..'true' then
blacklist = true
print(blacklist)
end
if msg == 'k/blacklist'..' '..'false' then
blacklist = false
print(blacklist)
end
end
end)
if blacklist == true then
local breakstart = true
while true do
wait(0.1)
print('blacklisting')
plr.Backpack.ChildAdded:Connect(function(child)
wait(0.1)
if child.Name == 'SubspaceTripmine' then
game.ReplicatedStorage.BlacklistNotify:FireClient(plr)
child:Destroy()
local breakstart = true
end
end)
if breakstart == true then
breakstart = false
break
end
end
end
end)
I believe the issue with this script is that you are breaking the while loop if breakstart is true. Before the while loop runs, the breakstart is already set to true, which is likely to be the reason why it seems the loop doesn’t start or end.
Set the breakstart to false before running the while loop.
if blacklist == true then
local breakstart = false
while true do
wait(0.1)
print('blacklisting')
plr.Backpack.ChildAdded:Connect(function(child)
wait(0.1)
if child.Name == 'SubspaceTripmine' then
game.ReplicatedStorage.BlacklistNotify:FireClient(plr)
child:Destroy()
local breakstart = true
end
end)
if breakstart == true then
breakstart = false
break
end
end
end
end)
This doesn’t seem to work. The loop doesn’t stop after the child is found. When breakstart is set to true at the start it’s able to stop the loop temporarily to prevent spamming of the notifications.
I just noticed this, it seems you have created another variable of the same name. Maybe that could also be the issue?
if blacklist == true then
local breakstart = false
while true do
wait(0.1)
print('blacklisting')
plr.Backpack.ChildAdded:Connect(function(child)
wait(0.1)
if child.Name == 'SubspaceTripmine' then
game.ReplicatedStorage.BlacklistNotify:FireClient(plr)
child:Destroy()
breakstart = true -- removed 'local' from here
end
end)
if breakstart == true then
breakstart = false
break
end
end
end
end)
The same problem is still happening, but something that I did notice is that it does stop the printing of “blacklisting”.
Strange.
Also, I don’t think you need to use the ChildAdded in a While loop, you can just check every 0.1 seconds if the item exists in the backpack or not.
See if this code does any difference:
if blacklist == true then
local breakstart = false
while true do
task.wait(0.1)
print('blacklisting')
if plr.Backpack:FindFirstChild("SubspaceTripmine") then
task.wait(0.1)
game.ReplicatedStorage.BlacklistNotify:FireClient(plr)
child:Destroy()
breakstart = true
end
if breakstart then
breakstart = false
break
end
end
end
end)
It’s still not working, I tried to fix this by making a variable that permanently breaks the loop, but it wouldn’t work for some reason. It only stops the loop once the gear appears in your inventory whether blacklist is true or not.