Edit: I forgot to add the other "not" in the if statement, sorry about that
I have a script that's supposed to cycle through a group of items in my game, and check to see if they're missing from the map or a players backpack. If an item is missing, it would pull a clone of it from ServerStorage and place it where it'd normally be. It seems like the script works for the most part, but it can't tell if an item is missing or not (where the if statement is). This is my script:
items = {"Keycard 1", "Keycard 2", "Keycard 3", "Keycard 4", "Keycard 5", "Keycard Omni", "SCP-173"}
amount = #items
game.ReplicatedStorage.Events.ResetItems.OnServerEvent:Connect(function(client) -- when the player loads a new game
wait(1.5)
local workspaceitems = workspace.RegenableItems
local saveditems = client.Items
repeat -- cycle through to check for missing items
wait(.1)
if not workspaceitems:FindFirstChild(items[amount]) and saveditems:FindFirstChild(items[amount]) then -- if the item doesnt exist, make a clone
local itemclone = game.ServerStorage.RegenStorage:FindFirstChild(items[amount]):Clone()
itemclone.Parent = workspace
end
amount = amount - 1
until
amount == 0
amount = #items -- reset item cycle
end)
Thanks in advance for any help!

3 comments
How about when an item as gone missing you regenerate it fully, like when a keycard is gone just get the player’s inventory and the keycard and put it fresh in the player’s inventory.
It looks like your loop only runs through all items once after a new game has loaded and then stops.
It could be more efficient to just replace the item as it is deleted instead of having to loop through all items and check to see if it's missing first.