Pretty much the title.
For example:
part = -- lets say this is unknown, and it was defined some other place. just ignore this line theOtherCommand = -- also unknown
My question is, how do I execute "theOtherCommand"?
To clarify, let's say
theOtherCommand = part.CanCollide = false
I wouldn't know the value though, but I still need to execute it. The value of theOtherCommand came from something that could have made the value anything. How do I execute it?
My first idea was:
function runCommand(theOtherCommand) -- yes, it was received as an argument from another function theOtherCommand end
That didn't work though, as it gave me an error on end that said it expected an identifier or something, so that got ruled out. What way is there, if it exists?
The problem here is, you can't anything other than a function, string, int, userdata, table or bool in a variable, meaning you can't put other code.
Here are my solutions:
Solution 1: Loadstring
This will only work if loadstring
is enabled.
local commandToRun = "part1:Destroy()" -- I'm not entirely sure if you can use variables in loadstring though function executeCommand(cmd) return loadstring(cmd) end executeCommand(commandToRun)
Solution 2: Function
function deletePart(part) part:Destroy() end deletePart(game.Workspace.Part)
Hope I helped!
~TDP