local weldi = part:FindFirstChild("WeldConstraint")
if weldi ~= nil then
weldi:Remove()
end
if weldi ~= not nil then
local char = player.Character or player.CharacterAdded:Wait()
local weld = Instance.new("WeldConstraint")
weld.Parent = part
weld.Part0 = part
weld.Part1 = char.HumanoidRootPart
end
Obviously the weld constraint was created and the first if condition did not pass(it was nil). Then if it wasn’t found, a weld would be created. Logically from top to bottom.
Some other notes:
Instance:Remove() is deprecated, use Instance:Destroy()
A complete solution is easy, I simply used the else statement for cases if the weld is not found.
local weld = part:FindFirstChild("WeldConstraint")
if weld then
weld:Destroy()
else
local char = player.Character or player.CharacterAdded:Wait()
weld = Instance.new("WeldConstraint")
weld.Parent = part
weld.Part0 = part
weld.Part1 = char.HumanoidRootPart
end