EDIT: I have made changes to the plugin because it was not working. I had the structure default to 1 which was incorrect and I have also removed the unnecessary currentScript:IsA("Script")
. Thanks for all your support!
EDIT2: I have made changes to the plugin so now it uses events instead of the while wait loop. This is highly more efficient and the plugin now instaly inserts commas instead of the 0-0.1 second wait. Thanks again for all of your support and suggestions!
Introduction
Hello developers, today as I was browsing the DevForum, I came across a feature request that I thought I could make. The idea was simple, automatically putting commas in tables. I didn’t think it would be complicated so I decided to give it a go.
After like an hour of work, I had a working plugin and I decided to put it on here.
Demonstration
I should mention that you cannot delete the comma. If the plugin detects there should be a comma then it will continously put one in the script.
How it works
To dumb it down it bassically loops through each line. On a line, it will check if it has any brackets. If it does, then it will loop through each character. In the loop it will check each characters value. If the character is a “{” then it will increase the structure value by one. If it is a “}”, it will decrease. When it comes time to put the line together, it will check if it should either add a comma and an newline or just a newline. The check returns a comma if the bracket == “}” and the structure is over 0.
Code
game.StudioService.Changed:Connect(function()
local currentScript = game.StudioService.ActiveScript
connection = (connection and connection:Disconnect()) or currentScript and currentScript:GetPropertyChangedSignal("Source"):Connect(function()
local output = ""
local structure = 0
if task.wait() and currentScript then
local lines = currentScript.Source:split("\n")
for i,v in pairs(lines) do
local bracket,pos = v:gsub(" ","")
if string.find(v,"{") or string.find(v,"}") then
for i,char in pairs(string.split(v,"")) do
structure = char == "{" and structure + 1 or char == "}" and structure - 1 or structure
end
end
output = output..v..tostring((bracket == "}" and structure > 0) and ",\n" or tostring(i ~= #lines and "\n" or ""))
end
currentScript.Source = output
end
end)
end)
Conclusion
In all, it inserts commas. But I don’t reccommend this plugin because I did not test it with many situations. But, from the situations I did test, it never had a problem.
I made a plugin install if you want, but I literally made this in about an hour so there might be bugs.