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

Why does not my for-do loop run, but other parts of the code do?

test2(line 27) gets printed out, but test(line 29) doesn't. Here is the code:

local dmg = 0

local hasHit = false

local function WoodHit(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
	print(hum)
	print(hum.Health)
	print(hit.Parent.Name)
	print(script.Parent.Name)
	
	if hum ~= nil and hum.Health > 0 and hit.Parent.Name ~= script.Parent.Name and hasHit == false then
		hasHit = true
		local hitParticle = game.ReplicatedStorage.WoodStuff.HitParticle:Clone()
		hitParticle.CFrame = hit.CFrame.LookVector * 2
		hitParticle.Parent = hit
		print(hitParticle.Parent:GetFullName())
		wait(.5)
		hitParticle:Destroy()
	end
end

script.Parent.ChildAdded:Connect(function(child)
	if child:IsA("Model") and child.Name == "WoodRelease" then
		print(child:GetFullName())
		local wood = script.Parent:WaitForChild("WoodRelease"):GetChildren()
		print("test2")
		for i = 1, #wood do
			print("test")
			wood[i].Touched:Connect(WoodHit)
		end
	end
end)

script.Parent.ChildRemoved:Connect(function(child)
	if child:IsA("Model") and child.Name == "WoodRelease"then
		hasHit = false
	end
end)

1 answer

It probably means the number of wood is 0 you can check how many there are by adding a

print(#wood)

after test2 print

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