1

How do I check if a weld has been broken?

Hello all, I'm relatively new to Lua programming, and was wondering how I could check if a WeldConstraint between two parts has broken, and then if it has, activate a ParticleEmitter briefly. After doing some research I found that .Active can be used to check whether a weld is active or not, and came up with this code:

local part = script.Parent
local originalPosition = part.Position
while true do
if (part.WeldConstraint.Active == false) and (part.Position.Magnitude > (originalPosition.Magnitude+1)) then
part.ParticleEmitter.Enabled = true
wait(2)
part.ParticleEmitter.Enabled = false
script:Destroy()
end
end


Unfortunately, the script does not work whatsoever. If anyone knows how else this would be possible, please let me know. Thank you.

0
Edited 14 days ago

Always put wait() at the start of a loop so it doesn't error or in worse cases, crash your game. Try checking the distance between part.Position and originalPosition by subtracting them then get the Magnitude (distance) of the difference and check if the Magnitude is equal to/greater than 1.

I recommend using task.wait() than wait() is because it is faster than wait(). task.wait() takes 1/60 of a second while wait() takes 1/30 of a second.

And also make sure the script is a normal script not a local script.

local part = script.Parent
local originalPosition = part.Position

while true do

if (part.WeldConstraint.Active == false) and ((part.Position - originalPosition).Magnitude >= 1) then
part.ParticleEmitter.Enabled = true
part.ParticleEmitter.Enabled = false
script:Destroy()
end
end


Hope this helps!

0
Hey T3, thank you so much for your reply. I tried to implement the new script that you suggested but, unfortunately, I'm having no luck with it working. I think one problem is with the use of GetPropertyChangedSignal() because I read this post (https://devforum.roblox.com/t/how-do-i-detect-if-a-weld-has-been-broken/253582) which states that WeldConstraints do not fire signals when changed. bear16225 7 — 14d
0
Despite this, however, I believe the real issue lies somewhere else because after replacing the function with a while wait() loop, it still does not seem to work. I don't think there is a problem with the ParticleEmitter either because I modified it to just change the BrickColor, and nothing happens. bear16225 7 — 14d
0
Okay, thanks for the info! I never knew WeldConstraint's Active property doesn't fire signals. I'll change my answer in a bit. T3_MasterGamer 1002 — 14d
0
while task.wait() do, and while true do task.wait() does the same thing. T3_MasterGamer 1002 — 14d