How would I know when an Enum value changes?

So I have the next code:

local userSettings = UserSettings():GetService("UserGameSettings")
local qualityLevel = userSettings.SavedQualityLevel

qualityLevel.Changed:Connect(function()
	if qualityLevel <= Enum.QualityLevel.Level09 then
		script.Parent.Lower.Visible = true
	elseif qualityLevel >= Enum.QualityLevel.Level10 then
		script.Parent.Lower.Visible = false
		script.Parent.Automatic.Visible = false
	elseif qualityLevel == Enum.QualityLevel.Automatic then
		script.Parent.Automatic.Visible = true
	end
end)

but its erroring this:

Changed is not a valid member of "Enum.SavedQualitySetting.QualityLevel10

How would I detect if the value changes?

1 Like

An Enum value doesn’t have an event for firing when it is changed. Enum is similar to numbers and strings, and that they are just information/datatype.

I believe UserSettings have the Changed event and that the SavedQualityLevel is a property, so you should attach a Changed event to UserSettings. (Correct me if I’m wrong via message)

1 Like

@Quwanterz Is correct, it has a Changed event, but it’s better to use GetPropertyChangedSignal so it only fires on the property you need

UserSettings().GameSettings:GetPropertyChangedSignal("SavedQualityLevel"):Connect(function()
	if UserSettings().GameSettings.SavedQualityLevel.Value >= 5 then
		print("ok")
	end
end)

Is an example of how you’d do it with getting the Value property of an Enum, you can suit it to work with your needs

2 Likes

Thanks, I tried what @Quwanterz said, but now it gives me this error:

Players.octav20071.PlayerGui.Graphics.Graphics:6: attempt to compare EnumItem <= EnumItem

You can’t use Less than or equal to on Enums. On your enums you’re using for comparing, Level09 and Level10, add .Value after them, same goes for the current SavedQualityLevel, except for the Automatic statement, keep it as it is

1 Like

Can you give me a sample? I am not sure where to put the .Value thing, since I put it everywhere

Lets go back to the old code you had before

local userSettings = UserSettings():GetService("UserGameSettings")
local qualityLevel = userSettings.SavedQualityLevel

qualityLevel.Changed:Connect(function()
	if qualityLevel <= Enum.QualityLevel.Level09 then
		script.Parent.Lower.Visible = true
	elseif qualityLevel >= Enum.QualityLevel.Level10 then
		script.Parent.Lower.Visible = false
		script.Parent.Automatic.Visible = false
	elseif qualityLevel == Enum.QualityLevel.Automatic then
		script.Parent.Automatic.Visible = true
	end
end)

This would error because of the less than or equal operator on Enums, a simple would be change both of them to have .Value so

if qualityLevel <= Enum.QualityLevel.Level09 then

Would be

if qualityLevel.Value <= Enum.QualityLevel.Level09.Value then
1 Like

Well that solved the error. But now even if my level is 1 to 9, it doesn’t show the UI. (I tried to post a screenshot but that didn’t load)

Edit: nvm here

May I see your code to see what you have so far

I tested with 2 different codes. Here is the normal one:

local userSettings = UserSettings():GetService("UserGameSettings")
local qualityLevel = userSettings.SavedQualityLevel


userSettings.Changed:Connect(function()
	if qualityLevel.Value <= Enum.QualityLevel.Level09.Value then
		script.Parent.Lower.Visible = true
	elseif qualityLevel.Value >= Enum.QualityLevel.Level10.Value then
		script.Parent.Lower.Visible = false
		script.Parent.Automatic.Visible = false
	elseif qualityLevel == Enum.QualityLevel.Automatic then
		script.Parent.Automatic.Visible = true
	end
end)

And here a RenderStepped one: (if when starting game graphics are below 9 the UI will show, else if 10 then it won’t show. But changing the graphics don’t affect anything)

local userSettings = UserSettings():GetService("UserGameSettings")
local qualityLevel = userSettings.SavedQualityLevel

game:GetService("RunService").RenderStepped:Connect(function()
	if qualityLevel.Value <= Enum.QualityLevel.Level09.Value then
		script.Parent.Lower.Visible = true
	elseif qualityLevel.Value >= Enum.QualityLevel.Level10.Value then
		script.Parent.Lower.Visible = false
		script.Parent.Automatic.Visible = false
	elseif qualityLevel == Enum.QualityLevel.Automatic then
		script.Parent.Automatic.Visible = true
	end
end)

It’s because it’s storing a previous value, put

local qualityLevel = userSettings.SavedQualityLevel

Inside of the Changed event, and use :GetPropertyChangedSignal("SavedQualityLevel") instead so it listens for that property only

local userSettings = UserSettings():GetService("UserGameSettings")

userSettings:GetPropertyChangedSignal("SavedQualityLevel"):Connect(function()
	local qualityLevel = userSettings.SavedQualityLevel
	if qualityLevel.Value <= Enum.QualityLevel.Level09.Value then
		script.Parent.Lower.Visible = true
	elseif qualityLevel.Value >= Enum.QualityLevel.Level10.Value then
		script.Parent.Lower.Visible = false
		script.Parent.Automatic.Visible = false
	elseif qualityLevel == Enum.QualityLevel.Automatic then
		script.Parent.Automatic.Visible = true
	end
end)
3 Likes

I hope you find this useful for you, ill try to make it as simple as possible so you can make a similar one:

Script.Parent.Changed:Connect(function()
if Script.Parent.qualityLevel == Enum.qualityLevel.Level09  then
 --Code here
 else
 end
end)
1 Like

Thanks! It worked! I just need to tune some stuff for me and it will be done! Again, thank you!

1 Like