I want to make a “:tobool” function.
When I try to make it a bool for any word that is a string called true it gives me no errors
I have went on youtube.com
I want it to make a string from a variable/value or a string to true but it will not work. but when I try to make it any word with like true, True, TruE it only works for true same as false I have it inside my ModuleScript.
function functionMod:tobool(instanceVal)
if instanceVal == "true" then
instanceVal = true
elseif instanceVal == "false" then
instanceVal = false
end
end
(Sorry for not much detail didnt know what to add)
I changed it alot sorry wrong topic it was my old read it again sorry 
Return the value instead. It doesn’t work since you are setting a string value to a boolean value.
function functionMod:tobool(instanceVal)
if instanceVal == "true" then
return true
elseif instanceVal == "false" then
return false
end
end
-- Now to test it
local variable = "true"
variable = functionMod:tobool(variable)
1 Like
Ok that also helped I just added it too 
But I also need it on my other thing read the thing again I mistakenly did my old post I was gonna add
sry
To add onto @Friendly4Crafter, to do what you wanted, check if what was given is a string and then use :lower() to lower case it
function functionMod:tobool(instanceVal)
if type(instanceVal) ~= "string" then
return nil
end
if instanceVal:lower() == "true" then
return true
elseif instanceVal:lower() == "false" then
return false
end
end
1 Like
So it auto matically lowers it ok ima try 
I am also trying to convert the string to a bool
Yes this will do as you want, it firsts checks if you passed in a string, and then lower cases that string and see if it equals to “true” or “false”
I know but it still prints this the string = to the variable which is this "True"
I will shpw all scripts rn
--module
function functionMod:tobool(instanceVal)
if type(instanceVal) ~= "string" then
return nil
end
if instanceVal:lower() == "true" then
return true
elseif instanceVal:lower() == "false" then
return false
end
end
--script
local functionMod = require(script.FunctionModule)
local trueval = "True"
functionMod:tobool(trueval)
print(trueval)
So instead of it being a string it goes straight to true or false so the bool
The way it works is that it returns it, right now you’re not caring about the return
local trueval = "True"
print(functionMod:tobool(trueval))
Ok but I am trying to change the variable so lets say it was true like this
local var = "TrUE"
-- i want it to convert to
local var = true
So instead of having to print the functionMod:tobool(var) I can just print the var
Then put the function as the assignment to truval…
local trueval = "True"
trueval = functionMod:tobool(trueval)
1 Like
Ok lemme try that
Sorry I am trying to make my own custom functions module for roblox
tysm this made me soo happy thanks 
1 Like