Hello! I have been trying out a few simple code things, and I found possibly the best way for my variable to be called is from inside a function. Here is my code:
local X = Instance.new("StringValue", workspace) -- Create The String Value
local Y = true -- Set Y To True As An Example
X.Value, X.Name = function() if Y then return true, "Test" else return false, "Bad Test :((((" end end -- Function To Set The Value Of X And The Name?
I was curious if this would work or if I should do something else to get this kind of result?
Solution:
function Z(Y) if Y then return "true", "Test" else return "false", "Bad Test :((((" end end local X = Instance.new("StringValue", workspace) -- Create The String Value
local Y = true -- Set Y To True As An Example
X.Value, X.Name = Z(Y) -- Function To Set The Value Of X And The Name?
local X = Instance.new("StringValue", workspace) -- Create The String Value
local Y = true -- Set Y To True As An Example
X.Value, X.Name = function() if Y then return true, "Test" else return false "Bad Test :((((" end end -- Function To Set The Value Of X And The Name?
local X = Instance.new("StringValue", workspace) -- Create The String Value
local Y = true -- Set Y To True As An Example
X.Value, X.Name = function() if Y then return true, "Test" else return false, "Bad Test :((((" end end -- Function To Set The Value Of X And The Name?
You’re trying to set them to a function without calling the function. Essentially you’re just setting x.Value to a new function (which doesn’t work). Either call the function or use ternary* instead, like so:
X.Value, X.Name = Y, Y and "Test" or "Bad test :(((("
You were returning the values from the function correctly, the function was just never called. Not calling a function means it won’t return anything, as you’re just referencing the function and not using it.
You can just change the code to suit your needs, like any other code. boolean and firstResult or fallback should work in a more general sense than this one situation, as long as firstResult isn’t false or nil.
function Z(Y) if Y then return "true", "Test" else return "false", "Bad Test :((((" end end local X = Instance.new("StringValue", workspace) -- Create The String Value
local Y = true -- Set Y To True As An Example
X.Value, X.Name = Z(Y) -- Function To Set The Value Of X And The Name?