Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

For each island found destroy() not working?

Asked by 5 years ago
Edited 5 years ago

So I have this folder in workspace called InslandSlots and each slot it has a model called Island.

After each round I wan't it to destroy() the model but I keep getting the error: ServerScriptService.Rounds:15: attempt to index a nil value

Server Script: --Rounds wait() while true do --Preparing round Status = "PREPARING ROUND" UpdateStatus:FireAllClients(Status) local Islands = game.Workspace.IslandSlots:GetChildren() for i = 1, #Islands do local Island = Islands[i] Island:FindFirstChild("Model"):Remove() wait() end wait(10) end

0
This might not be helpful, so I'm not making it an answer, but normally for tables I use for i, var in ipairs(table) do as it automatically just cycles through the table. You then wouldn't have to use Islands[i], as var would already carry the same value that that would. I honestly don't see any problems other than that, except for the infinite loop created by while true do, when this seems to hap msuperson24 69 — 5y
0
pen only once, but this could just be because I don't know the full scope of the script. msuperson24 69 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

I tried to create a similar environment that I could decipher from your code, my folder is depicted here: https://prnt.sc/naby2w

I used similar code to yours without while true do because I was only attempting to do it once. This is what I procured in a script that was inserted into ServerScriptService:

wait()
local islands = workspace.IslandSlots:GetChildren()
for i, island in ipairs(islands) do
island:FindFirstChild("Model"):Destroy()
print("island destroyed")
end

From just running that, I was successful, however, as I said in my comments, I don't know the full scope of your script or the workspace you are dealing with. On the oft chance that you are using Island:FindFirstChild("Model") and model isn't actually a descendent of Island, that would be your problem, but otherwise I don't honestly know what is going wrong with your script. Hope you figure it out, and that I could potentially provide some insight.

0
thanks for your insight. I've figured it out. retrobricks 162 — 5y
Ad

Answer this question