Hello. I noticed that my script is seemingly breaking when attached with an if statement. My goal is to read if an argument is a model with a humanoid (like the player) and detect when something isn’t.
Issue: Once it detects something else other than what meets the requirements it just stops.
function GridModule.InsertToGrid(UnitsToInsert)
for index, unit in pairs(UnitsToInsert) do
print(unit)
if unit:IsA("Model") and unit:FindFirstChild("Humanoid") then
print("Valid!")
else
warn("Not Valid!")
end
end
end
Response for Edit: Yes. It is supposed to check if it is a model and has a humanoid. If it does not, then it is supposed to print “Not Valid”, which doesn’t occur.
Here is the formatting of the code with the print statements.
print("Start!")
for index, unit in pairs(UnitsToInsert) do
print(unit)
if unit:IsA("Model") and unit:FindFirstChild("Humanoid") then
print("Valid!")
else
print("Not true!")
end
print("Stopped!")
end
end
It is stopping at the second loop (where it prints “Jim”), oddly enough. If I replace “Jim” with something that meets the requirements, it works until it finds something that does not.
I did some moving around in the script where it is starting and, as odd as it sounds, I do actually get an error. Here’s the code for when the function is playing:
repRemotes.BattleBegin.OnServerEvent:Connect(function(player)
local WaitForLoad = coroutine.create(function()
print("Waiting...")
coroutine.yield()
print("Grid Created!")
end)
game.ServerStorage.Remotes.GridCreated.Event:Connect(function()
coroutine.resume(WaitForLoad)
end)
gridModule.CreateGrid(workspace.TestModel)
coroutine.resume(WaitForLoad)
print("Running!")
wait(5) -- for testing purposes for this case.
gridModule.InsertToGrid({player.Character, "Jim", "Steve", "Bill", "John"})
end)
Interestingly enough, I DO get an error when I wait.
Maybe its something to do with trying to run :IsA or :FindFirstChild on a string value. Its not an instance, those functions are to be used on an instance.(I think, maybe)
IDK why it wouldn’t error faster if that were the case though, strange.