Created
November 7, 2022 14:53
-
-
Save Anaminus/acf90d219c56ac4053f2ef7543af8cf1 to your computer and use it in GitHub Desktop.
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
--[[ | |
Usage: | |
rbxmk run fix-welds.rbxmk.lua PATHS | |
Scans each given file or directory path for rbxm and rbxmx files. For each such | |
file, scans for WeldConstraint instances. For each WeldConstraint, sets the | |
Enabled property depending on the State property. | |
This allows Rojo to properly sync the enabled state of WeldConstraints. | |
]] | |
local function fixWelds(file) | |
local model = fs.read(file) | |
for _, instance in ipairs(model:GetDescendants()) do | |
if instance.ClassName == "WeldConstraint" then | |
instance.Enabled = instance.State ~= 0 | |
end | |
end | |
fs.write(file, model) | |
end | |
local function scanPath(filePath) | |
local files = fs.dir(filePath) | |
if files then | |
for _, file in ipairs(files) do | |
scanPath(path.join(filePath, file.Name)) | |
end | |
else | |
local ext = path.split(filePath, "ext") | |
if ext == ".rbxm" or ext == ".rbxmx" then | |
fixWelds(filePath) | |
end | |
end | |
end | |
for _, filePath in ipairs({...}) do | |
scanPath(filePath) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment