Alright so what I have here is a part of a script for a water wave.It works just fine only problem is that the for doesn't break and I can't quite get it why.Basically if a part has a 'Protection' inside it(A value), and my wave hits it, my 'ok' variable becomes true thus it should break the for if still inside it.Instead, it goes all the way until the end and only after that it destroys my parts.

local ok = false

RemoteEvent.OnServerEvent:Connect(function(player)
	for i = 1, 7 do
		if ok then
			break
		end	
		local x = script.Wave:Clone()
		x.Size = Vector3.new(25*i, 25*i, 25*i)
		x.CanCollide = false
		x.Anchored = true
		x.Parent = workspace
		x.CFrame = player.Character.Torso.CFrame*CFrame.new(0, 0, -10*i)
		x.Touched:connect(function(hit)
			local damage = 25
			if hit:FindFirstChild("Protection") then 
				ok = true
				x:Destroy()
				return
			end
		end)
		game.Debris:AddItem(x, 10)
		wait(0.01) 
	end
end)

2 comments

0

"hit" only shows the brick that is touching. Not the model, do hit.Parent:FindFirstChild("Protection") unless protection is inside of the brick, get back to me if this is the case and I'll look some more.

0

It's inside a Brick, not a model.