Making Moving parts local not working correctly

tried using this to make a disappearing part local for the player, this type of scripts works perfect with grouped kill brinks but when I moved a different function into the area it doesn’t work, what did I do wrong?

local lasers = workspace.ObbyStructure.SpaceTunnel:GetChildren()

while true do
	for i, child in pairs(lasers) do
		if child:IsA("BasePart") then
			
			function onTouched(hit)
	    script.Parent.Transparency=1 
    script.Parent.CanCollide = false
	 
	    wait(4) 
	    script.Parent.Transparency=0
	    script.Parent.CanCollide = true
	end
	 
	script.Parent.Touched:connect(onTouched)
		end
	end
	wait(0.01)
end

The “for I” check that you did at the beginning of the script limits the latter onTouched function to acting on one of the found parts. Of course if you touch it for a long enough period of time it will still change a lot of those parts quickly, but it’s definitely not the solution you’re looking for.

Also it’s good practice to add a small wait after a while loop, just in case.

1 Like