Hello! I’m really a bit stumped by a seemingly simple (probably is) issue with a Parts/Model deleter I’m making.
Basically, I’m working on a setting in a game I’m working on that locally deletes a bunch of things inside of a building because it’s a little performance taxing on older machines.
Snippet of code I can’t get working:
local upgradesToIgnore = {"GFWalls", "FirstFloor", "FFWalls", "SecondFloor", "Door", "DontDelete"}
for i, v in pairs(ylw:GetDescendants()) do
if upgradesToIgnore[v.Name] == nil then
v:Destroy()
end
rnSVC.RenderStepped:Wait()
end
Now, what I think this should be doing is checking if the part’s name it’s found is in the “upgradesToIgnore” table and if the parts name is nil (i.e not in the table, thus returning nil) then it should skip that part and do the next for loop iteration.
Thing is, it deletes all the parts anyway, what am I doing wrong here?
local upgradesToIgnore = {["GFWalls"] = "GFWalls", ["FirstFloor"] = "FirstFloor", ["FFWalls"] = "FFWalls", ["SecondFloor"] = "SecondFloor", ["Door"] = "Door", ["DontDelete"] = "DontDelete"}
for i, v in pairs(ylw:GetDescendants()) do
if upgradesToIgnore[v.Name] ~= nil and upgradesToIgnore[v.Name] ~= v.Name then
v:Destroy()
end
rnSVC.RenderStepped:Wait()
end
Made your change to the ignorelist and updated the for loop to work accordingly, but I still have the same problem. Have I done the dictionary correctly? I haven’t really worked much with dictionaries like this so I’m fairly clueless.
Thanks for pointing out the incorrect format though, I should’ve spotted this as I use arrays fairly frequently in other things (efficiently, do not fear)
EDIT: Noticed a mistake I made, updated code (still doesn’t work tho, now it deletes nothing)
local upgradesToIgnore = {["GFWalls"] = "GFWalls", ["FirstFloor"] = "FirstFloor", ["FFWalls"] = "FFWalls", ["SecondFloor"] = "SecondFloor", ["Door"] = "Door", ["DontDelete"] = "DontDelete"}
for i, v in pairs(ylw:GetDescendants()) do
if not upgradesToIgnore[v.Name] then
v:Destroy()
end
rnSVC.RenderStepped:Wait()
end
In the first check you check if the string is a key in the dictionary, which it may or not be. If it is, the next check asks if the value that belongs to the key is not equal to the key itself, but in your case the key and value are always the same.
You can simply delete that check and only keep this part:
upgradesToIgnore[v.Name] ~= nil
You just want to know if the key exists in the table. What its value is does not matter. Usually I would just set the value to true as suggested in the first reply.
I changed it to just the simple check you suggested and also set all the values in the dictionary back to true but it still deletes the parts I don’t want it to.
The parts in workspace are definitely called what I put in the ignore list.