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.
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 task.wait() if (part.WeldConstraint.Active == false) and ((part.Position - originalPosition).Magnitude >= 1) then part.ParticleEmitter.Enabled = true task.wait(2) part.ParticleEmitter.Enabled = false script:Destroy() end end
Hope this helps!