One weld script makes multiple welds

Hi,
When I check the welds there seem to be 2of them (and once 3) where only one should be. Anyone know why?

--weld
wait(0.5)
local t = true
if t then
	for i,v in pairs(script.Parent.Parent.RentalShuttle_Static_01:GetChildren()) do
		local t = Instance.new("WeldConstraint")
		print(v)
		t.Parent = v
		t.Part0 = script.Parent.Parent.Body
		t.Part1 = v
		print("Weld created")
	end
	t = false
end
print("T PRINTED")

Not running
Screenshot 2022-04-03 at 18.57.03
Running
Screenshot 2022-04-03 at 18.59.20

T is printed twice as well. It shouldn’t be. But even though it is printed twice, “wings” always has 3 weld constraints even though it should only have 1, which is even stranger

It’s most likely due to your script being re-ran before the debounce is set to false. Actually the debounce wouldn’t matter because it would just get reset in that case.

One fix is to set it to false right away before the WeldConstraints are created, and having the script outside the model.

Another is to check if there is already a WeldConstraint inside the model before making a new one.

And another option is to have the debounce outside the script in a BoolValue object so if it gets re-ran, its not using a new debounce.

1 Like

Checking if there was already a pre-existing weld constraint worked. Wait(2) also works. it was probably running multiple times for some reason. Ty.