Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

For each island found destroy() not working?

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:

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```

2 comments

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

0

pen only once, but this could just be because I don't know the full scope of the script.

1 answer

✓ Accepted answer

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.

1 comment

0

thanks for your insight. I've figured it out.

This discussion is preserved as it was. New answers, comments, and votes are closed.