Looping through a table for a PlaceID

Hey, I’m currently trying to achieve a place Id check through a table, so if it finds the player in a certain place then it clones a script and parents it to their weapon. My only issue so far is that the table detects only 1 place id inside of the table and not the other 2.

I have tried using a for i,v loop for my table however it seems to stop completely if it doesn’t find the correct placeid, I have also tried using table.find still the same problem.

TLDR: It loops through the table, detects only the “TECH” one despite being in the other game

local placelist = {
   [11893177941] = {  -- DT Obsidius
      Config = "Configuration_Obsidius",
      Tool = "M-71",
      ID = "11893177941",
   };
   [7730050913] = { -- TECH
      Config = "Configuration_Vesra",
      Tool = "M-71",
      ID = "11893177941",
   };
}

for i, data in pairs(placelist) do
   if tool:FindFirstChildWhichIsA("ModuleScript") then return end

   if i == game.PlaceId then
      print("FOUND PID")
      local CurrConfig = Configs:FindFirstChild(data.Config):Clone()
      CurrConfig.Parent = tool
   else
      print("COULDNT FIND PID")
      local RevConfig = Configs:FindFirstChild(tool.Name):Clone()
      RevConfig.Parent = tool
   end
   end

I think this may be your issue. You’re using the return keyword, which will break out of the for loop, preventing it from iterating any further.

Try substituting return for the continue keyword. This will allow you to skip the current iteration and move onto the next, rather than prematurely end it altogether.

1 Like

Thank you so much, that line was indeed causing it to break the loop; though using continue didn’t fix it, I removed that line and added other checks which seem to work perfectly now. Thanks again.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.