that would work for this scenario however if im doing something like
local instance = workspace.Part
local position = Vector3.new(15,15,15)
local testScript = workspace.TestScript
testScript.Source = 'instance.Position = position'
I do have another idea, I could try turning the full variable value into a string but i’m not fully sure how to do so. I tried using something like tostring but that only returns a bit of the variable.
This would bring up the error of trying to concat a vector3 object and a string so you would just do a quick change such as:
local position = Vector3.new(15,15,15)
testScript.Source = string.format('%s.%s = Vector3.new(%s)', instance:GetFullName(),
--[[part propertie name]]"Position",
--[[new value]] tostring(position))
Unfortunately this means you have to change the string you are formatting for each object type. However you can detect the object type using typeof() which return the object name in the form of a string.
local function newToString(value)
if typeof(value) == "Vector3" then
return ("Vector3.new(%s, %s, %s)"):format(value.X, value.Y, value.Z) -- replace %s with respective value
elseif typeof(value) == "CFrame" then -- another example
return ("CFrame.new(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"):format(value:components())
end
end
local position = Vector3.new(15,15,15)
testScript.Source = string.format('%s.%s = %s', instance:GetFullName(),
"Position", -- part propertie name
newToString(position)) -- "Vector3.new(15,15,15)"
-- Another exaple:
local cframe = CFrame.new(15,15,15)
testScript.Source = string.format('%s.%s = %s', instance:GetFullName(),
"CFrame", -- part propertie name
newToString(cframe)) -- "CFrame.new(15, 15, 15, 1, 0, 0, 0, 1, 0, 0, 0, 1)"
repr is a debugging tool whose output looks distinctly code-like. It is not a data serialization tool. You should not be using it to store data or generate code, even though parts of its output may look appropriate for that.
(edit: although, I appreciate the shout-out, perhaps some part of repr can be used in OP’s case! didn’t want to sound unnecessarily hostile lol)