Yeah but what does it print for the player.Character when you run the script?
Oh, it simply prints my name. For example, it appears as: “Dreisang”
Here is an example as to what it does. It stops at “Jim” in this regard, the second argument.
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.
Okay we can try this:
- Add a print statement outside the for in loop
- Add a print statement beneath the if statement
The content of these can be whatever, we just need to determine where the script stops, and if it stops at the else statement or not.
Once done post the result.
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
Here is the output:
Can you also add a statement beneath the loop?
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 need you to add the statement beneath the for-in loop to check if the loop finishes. I doubt it does but it’s best to double-check.
I just want to see it to find out if the function is terminating or the loop.
Actually… no. It STOPS.
It does not print “Stops”. It is likely because it is terminating for some cause.
Wait, so maybe the function is terminating? That’s not what I expected.
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.
It is coming from this line here:
if unit:IsA("Model") and unit:FindFirstChild("Humanoid") then
print("Valid!")
end
It’s the if statements. Maybe split them into separate statements? I have honestly no idea what to do.
This would be so much easier if I had studio open.
No luck, unfortunately. It’s good that we found that it is indeed terminating. I’ll try a few different things. I appreciate your attempt at helping!
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.
Good point. It works just fine when it detects a humanoid, only stopping if it doesn’t.
Put some workspace parts in your list and try it. Should print fail for the parts and valid for the humanoid.
Yeah, it actually seems to work that way. So… if it’s a string then it breaks it entirely.
You can probably use typeof to weed out the strings or whatever else might be in the table:
maybe typeof will tell you if its an instance and you can proceed with your if checks