Skip to content

Instantly share code, notes, and snippets.

@spotco
Created March 15, 2017 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spotco/e696dee6b6cf1407acd3e83d988182cf to your computer and use it in GitHub Desktop.
Save spotco/e696dee6b6cf1407acd3e83d988182cf to your computer and use it in GitHub Desktop.
Weld.lua
local weldName = string.format(
"Weld(%s)_(%s)",
script.Parent.Name,
script.Parent.WeldTarget.Value.Name
)
if script.Parent:FindFirstChild(weldName) ~= nil then
script.Parent:FindFirstChild(weldName):Destroy()
end
local weld = nil
local function make_weld()
weld = Instance.new("Weld");
weld.Name = weldName
weld.Part0 = script.Parent
weld.Part1 = script.Parent.WeldTarget.Value
weld.C1 = CFrame.new(0,0,0)
weld.C0 = weld.Part0.CFrame:inverse() * weld.Part1.CFrame
weld.Parent = script.Parent
end
make_weld()
script.Parent.ChildRemoved:Connect(function(instance)
if instance == weld then
make_weld()
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment