How would I go about making a format script that turns local variables and global variables in to the typeof() of what they equal eg
local a = 1
local b = ""
local c = workspace
a = 2
b = "1"
c = game.ReplicatedStorage
--turn that ^ Into this |
local number = 1
local string = ""
local Instance = workspace
number = 2
string = "1"
Instance = game.ReplicatedStorage
Just remember you can only write to the source through plugin scripts or the command bar.
Use some basic string manipulation:
--// something like
local source = workspace.Script
source.Source = source.Source:gsub("local%s-(%w+)%s-%=%s-(%S+)%s?", function(a, b)
local _, c = pcall(function()return game[b:match("game%p(%w+)") or b] and "Instance" end);
if(tostring(c):match("is not a valid member")) then
print(b, " is not a member of game")
c = typeof(getfenv()[b] or tonumber(b) or b);
end
return "local "..c.." = "..b.."\n"
end)
so the source of a script under game.Workspace with this code:
turns into:
Note however that my string manipulation is a bit rusty and I know it can be improved (I’ll leave you to that for now) for instance quotes within a string could cause it to malfunction (I don’t know anymore since I’ve changed the code a lot, but the point is you can make several improvements to this - I don’t have a lot of time on my hands right now so this is just a rudimentary solution).
Again you can expand on this pretty easily, or just use an easier alternative if applicable now that you’ve seen one possible method.
Other than that you haven’t really provided any information at all so we can’t fix your current system, if you’d still like to make your own implementation work so you can at the very least learn something, provide us your attempt.