I was iterating through game:GetDescendants()
and was trying to compare each descendant’s ClassName
with a string.
I’m making a ‘disinfectant’ script for some friends.
But, every time I ran it in a test mode or real server, I got the following error on the line doing the comparison.
Error occured, no output from Lua
This error only seems to happen when I’m using values from an array - AKA making it able to ‘softcode’.
I tried doing it with a hardcoded comparison, and it did not throw the error.
Here’s my code:
local ClassesToRemove = {"RotateP"}
local NamesToRemove = {"Vaccine"}
local function IsInfection(Object)
for _,Class in pairs (ClassesToRemove) do
if Object.ClassName == Class then -->> Errors here
return true
end
end
for _,Name in pairs (NamesToRemove) do
if Object.Name == Name then
return true
end
end
return false
end
for _,Descendant in pairs (game:GetDescendants()) do
if IsInfection(Descendant) then
Descendant:Destroy()
end
end
Any idea why this might be happening?
Thanks