Created
March 15, 2017 23:16
-
-
Save spotco/e696dee6b6cf1407acd3e83d988182cf to your computer and use it in GitHub Desktop.
Weld.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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