Help with rendering certain parts based on users graphics level

Hi!
I’m currently working on an open-world map and wanted to add some optimization (very basic). I was wondering how I would go about rendering a certain amount of parts(leaves) based on the users graphics level.
Here is my code

local GameSettings = UserSettings():GetService("UserGameSettings")
local run = game:GetService("RunService")
local Players = game:GetService("Players")

local userSettings = UserSettings():GetService("UserGameSettings")
local qualityLevel = userSettings.SavedQualityLevel
local stay = true
local function onGameSettingChanged(nameOfSetting)
	local canGetSetting,setting = pcall(function ()
		return GameSettings[nameOfSetting]
	end)

	if canGetSetting then
		print("Your ".. tostring(nameOfSetting) .." changed to: " .. tostring(setting))
		qualityLevel = userSettings.SavedQualityLevel	
		local children = game.Workspace.Vegitation.GroundVegitation:GetChildren()
		
		-- what do I do now
	end
end

GameSettings.Changed:Connect(onGameSettingChanged)

Hello,

To get the player’s graphics quality, run this code in a local script.

local GraphicsQuality = UserSettings().GameSettings.SavedQualityLevel

However, a couple of things to keep in mind,

Remember you might want to put it on a changed event as it will only return the current value.

And this code will return “Enum.SavedQualitySetting.QualityLevel”…(The current render status).

So a workaround would to get the value as an int, would be to do something like this:

function GetGraphics()
	for i=1, 10 do 
		if tostring(UserSettings().GameSettings.SavedQualityLevel) == "Enum.SavedQualitySetting.QualityLevel".. tostring(i) then
			return i
		end
	end
end

local GraphicsQuality = GetGraphics()

That code will then return a number in-between 1 and 10 of the player’s graphics.

Let me know how it goes!

2 Likes