Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

A Script that checks if the values are equal?

*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

3 answers

✓ Accepted answer

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:

  1. On line 11, you're using the 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.
  2. Following the first statement, you can use 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

If I helped, be sure to upvote/accept!

2 comments

0

Thanks but the the values For Loader version is at 1, But the module value is at 2.

0

Never mind, this really work, Thanks so much!

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

1 comment

0

Expect for the part when the values is at 2, It does not set to "Updated"

if valueA = valueB then

easy stuff dude

3 comments

0

lmao. Thats not equal to. Thats changing the value. To be equals to, it has to be x==y

0

What would be a proper in doing this for The Both values?

0

that's not how it works = is used to change a value into another value, to check if a is equal to b you gotta if a == b then, thats how operators work

This discussion is preserved as it was. New answers, comments, and votes are closed.