SmartValueService
Are you tired of checking values and making a valuebase according to the value?
Worry no more, because SmartValueService fixes this!
It is a simple module yet useful for developers who are tired of Roblox not having a global valuebase that stores everything like attributes
How to install:
- Get it from the Roblox library
How to use:
Once you have the module script, place it inside wherever you want, take into account that if you’re going to use it from the client you can’t require it from services that aren’t replicated to the client (such as serverstorage)
Now you should make a script and paste this code:
local PathToModule = game:GetService("ServerScriptService") --This is the path to the module
local SmartValueBaseModule = require(pathToModule.SmartValueService)
--Examples:
local classname1 = SmartValueBaseModule:GetClassName("Yummy")
--This will return "StringValue"
local classname2 = SmartValueBaseModule:GetClassName(true)
--This will return "BoolValue"
Usage:
This module is useful to use with Instance.new() according to the value
local PathToModule = game:GetService("ServerScriptService") --This is the path to the module
local SmartValueBaseModule = require(pathToModule.SmartValueService)
local classname1 = SmartValueBaseModule:GetClassName("Yummy")
Instance.new(classname1) --It will make a stringValue
Important notice:
Although this module will never error, your code can do so. If you use values that aren’t supported by valuebases, it will return nil
. Look at this code to see how to fix it if you are a beginner.
--This script will error
local PathToModule = game:GetService("ServerScriptService") --This is the path to the module
local SmartValueBaseModule = require(pathToModule.SmartValueService)
local classname1 = SmartValueBaseModule:ReturnClassNameAccordingToValue({})
--classname1 is nil because tables aren't supported inside valuebases!
--Therefore:
Instance.new(classname1) --Will error because of nil
--This script won't error
local PathToModule = game:GetService("ServerScriptService") --This is the path to the module
local SmartValueBaseModule = require(pathToModule.SmartValueService)
local classname1 = SmartValueBaseModule:GetClassName{})
--classname1 is nil
--Therefore:
if classname1 then --Will check if classname1 exists (you can also use ~= nil)
Instance.new(classname1) --Will error because of nil
else
--Code to run if it is not supported
end
Reason to use this module?
This module uses a dictionary that has stored each valuebase classname indexed by its typeof (“Instance”, “boolean”, etc…). Indexing dictionaries is much faster than using arrays with for loops or spamming else ifs because it retrieves the indexed value instead of searching for every value in the array.
Info:
The documentation is inside the modulescript
This module may be easy to create, but I wanted to make it to help some beginners, or even code what some may be lazy to do and just use stringvalues for everything (totally not me in the past) hehe! I hope you like it.