Help with my breakable glass

I am currently trying to make breakable glass for my gun, what would be the best way to get the children of a model and then make all of those have the same property? or is there a better way to do this

if result.Instance.Name == "Glass" then
					local glass = result.Instance
					print("About to start working")
					glass.CanCollide = false
					glass.Transparency = 1
					local glassSound = game:GetService("ReplicatedStorage").GlassSound:Clone()
					glassSound.Parent = glass
					glassSound:Play()
					wait(.5)
					glassSound:Stop()
					wait(10)
					glass.CanCollide = true
					glass.Transparency = 10
				end

The way I would do it getting the children using :GetChildren() and then use a for loop to do things to every child. (Also add if statements if you have other things like scripts as a child)

local Children = Parent:GetChildren()
for i = 1,#Children do
      local CurrentChild = Children[i]
       --Code:
       --(example:)
       CurrentChild.Name = "Random Name"
end

tell me if this works

1 Like