*I'm still learning at scripts, and i am new towards it! (Beginners learner)
This script check the Loader_Version to the Module_Version, When the scripts detect that the Value are not the same value it will Input the text to "Update_Required".
When the script detects the values are equal, It will input the text to "Updated".
--Value Locate local loader_Version = game.ReplicatedStorage.Versions --Example: Value is 1 local Module_Version = game.ReplicatedStorage.Offical_Version --Example: Value is 2 ---[[Updates Tab]]-- Updated = "Up-To-Date ?" Update_Required = "Loader! ?" while wait() do if loader_Version.Value == not Module_Version.Value then do script.Parent.Text = "Update: " .. Update_Required --When both value are not equal end end end if loader_Version.Value == 2 and Module_Version.Value == 2 then do script.Parent.Text = "Update: " .. Updated end end
I really don't think i did this right, Even tho i'm still learning i could like to learn from other peoples as well!
*Picture of the value's https://gyazo.com/8e3f4c2a4f7abc8628ac07c3bb413433
Firstly, let's clean up that code of yours. Clean code is essential to readability.
-- Value Locate local loader_Version = game.ReplicatedStorage.Versions --Example: Value is 1 local Module_Version = game.ReplicatedStorage.Offical_Version --Example: Value is 2 -- Updates Tab local Updated = "Up-To-Date ?" -- Reccomended to keep variables local local Update_Required = "Loader! ?" while true do if loader_Version.Value == not Module_Version.Value then script.Parent.Text = "Update: " .. Update_Required --When both value are not equal end if loader_Version.Value == 2 and Module_Version.Value == 2 then do script.Parent.Text = "Update: " .. Updated end wait() end
Now, we can easily see the errors:
not
operator, which isn't ideal in this case. To check for inequality, use ~=
or the less than (<
) operator in this case. Here you can learn more about the not
operator.else
to determine what happens otherwise. An if
statement works as follows: if (condition == true) then
... do stuff ...
else
... do something else, as condition is falsey ...
end
Meaning we could do something like this:
if Current_Version < Latest_Version then print("I need an update!") else print("I am up-to-date!") end
In plain English, this is checking if Current_Version
(the current version, respectively) is less than the Latest_Version
. If so, the program's version is less then the latest version, therefore needing an update. Elsewise, the program is fine.
Here's what it'd look like in your code:
-- Value Locate local loader_Version = game.ReplicatedStorage.Versions --Example: Value is 1 local Module_Version = game.ReplicatedStorage.Offical_Version --Example: Value is 2 -- Updates Tab local Updated = "Up-To-Date ?" local Update_Required = "Loader! ?" while true do if loader_Version.Value < Module_Version.Value then script.Parent.Text = "Update: " .. Update_Required else script.Parent.Text = "Update: " .. Updated end wait() end
Fixing your script, it would be:
--Value Locate local loader_Version = game.ReplicatedStorage.Versions --Example: Value is 1 local Module_Version = game.ReplicatedStorage.Offical_Version --Example: Value is 2 ---[[Updates Tab]]-- Updated = "Up-To-Date ?" Update_Required = "Loader! ?" while wait() do if loader_Version.Value ~= Module_Version.Value then -- "do" shouldn't be put after an if-then statement -- inequality is tested for using "~=", not using "== not" script.Parent.Text = "Update: " .. Update_Required --When both value are not equal end -- you had too many "end"s here if loader_Version.Value == 2 and Module_Version.Value == 2 then script.Parent.Text = "Update: " .. Updated end end
However, it's better to change the text only when the version updates instead of in a loop to save CPU cycles:
--Value Locate local loader_Version = game.ReplicatedStorage.Versions --Example: Value is 1 local Module_Version = game.ReplicatedStorage.Offical_Version --Example: Value is 2 ---[[Updates Tab]]-- Updated = "Up-To-Date ?" Update_Required = "Loader! ?" function checkUpdate() -- put everything in a function if loader_Version.Value ~= Module_Version.Value then -- "do" shouldn't be put after an if-then statement -- inequality is tested for using "~=", not using "== not" script.Parent.Text = "Update: " .. Update_Required --When both value are not equal end -- you had too many "end"s here if loader_Version.Value == 2 and Module_Version.Value == 2 then script.Parent.Text = "Update: " .. Updated end end checkUpdate() -- check update in the beginning function valueChange(property) if property == "Value" then -- if it's the "Value" property that changed: checkUpdate() -- check update end end loader_Version.Changed:connect(valueChange) -- when loader_Version changes Module_Version.Changed:connect(valueChange) -- when Module_Version changes
if valueA = valueB then
easy stuff dude