Low Graphics System Help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Hello! I have wrote a low gfx script to loop through all of the descendants in 2 folders when activated, then it will set an attribute to the part of it’s Material, BrickColor3, MaterialVariant, and if the part has the tag “LowGFX” it will set the parent’s path to an attribute and move the part with the tag into the LowGfxStorage folder in ReplicatedStorage.

For when the low gfx mode is deactivated, it will loop through the descendants of the LowGfxStorage folder to read the path attribute of the descendant and parent the part back to where it originally was. It will again loop through all of the descendants in the same 2 folders as before to set the Materials and Color back to normal.

I’ve made a function to create a string value of the path to the part inside the workspace, and another function to retrieve the parent instance from the string.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LowGfxStorage = ReplicatedStorage:WaitForChild("LowGfxStorage") --Folder to store parts
local ToggleLowGraphicsEvent = ReplicatedStorage:WaitForChild("ToggleLowGraphics")
local CooldownTime = 10
local lastUsageTimes = {} --cooldown table

local function getPath(instance)
	if not instance.Parent then
		return nil
	end
	local path = instance.Name
	local current = instance.Parent
	while current and current ~= game do
		path = current.Name .. "." .. path
		current = current.Parent
	end
	return path
end

local function getInstanceFromPath(path)
	local current = game
	for name in string.gmatch(path, "([^%.]+)") do
		print("Looking for:", name, "in", current.Name)
		current = current:FindFirstChild(name)
		if not current then
			print("Could not find:", name)
			return nil
		end
	end
	return current
end

local function setLowGraphics()
	for _, part in pairs(workspace:WaitForChild("Rooms"):GetDescendants()) do
		if part:IsA("Part") or part:IsA("MeshPart") then
			part:SetAttribute("OriginalPath", getPath(part))
			part:SetAttribute("OriginalMaterial", part.Material)
			part:SetAttribute("OriginalBrickColor", part.BrickColor)
			part:SetAttribute("OriginalMaterialVariant", part.MaterialVariant)
			part.Material = Enum.Material.SmoothPlastic

			if part:HasTag("LowGFX") then
				part.Parent = LowGfxStorage
			end
		end
	end

	for _, part in pairs(workspace:WaitForChild("GeneratedRooms"):GetDescendants()) do
		if part:IsA("Part") or part:IsA("MeshPart") then
			part:SetAttribute("OriginalPath", getPath(part))
			part:SetAttribute("OriginalMaterial", part.Material)
			part:SetAttribute("OriginalBrickColor", part.BrickColor)
			part:SetAttribute("OriginalMaterialVariant", part.MaterialVariant)
			part.Material = Enum.Material.SmoothPlastic

			if part:HasTag("LowGFX") then
				part.Parent = LowGfxStorage
			end
		end
	end
end

local function resetGraphics()
	if not LowGfxStorage then
		warn("LowGfxStorage folder not found in ReplicatedStorage.")
		return
	end

	for _, part in pairs(LowGfxStorage:GetChildren()) do
		local originalPath = part:GetAttribute("OriginalPath")
		if originalPath then
			local originalParent = getInstanceFromPath(originalPath)
			if originalParent then
				part.Parent = originalParent
			else
				warn("Original parent not found for part: " .. part.Name)
			end
		else
			warn("OriginalPath attribute not found for part: " .. part.Name)
		end
		
		part.BrickColor = part:GetAttribute("OriginalBrickColor")
		part.Material = part:GetAttribute("OriginalMaterial")
		part.MaterialVariant = part:GetAttribute("OriginalMaterialVariant")
	end
	
	for _, part in workspace:WaitForChild("Rooms"):GetDescendants() do
		if part:IsA("Part") or part:IsA("MeshPart") then
			local originalMaterial = part:GetAttribute("OriginalMaterial")
			if originalMaterial then
				--print("originalMaterial found")
				part.Material = originalMaterial
			end
			local originalBrickColor = part:GetAttribute("OriginalBrickColor")
			if originalBrickColor then
				--print("originalBrickColor")
				part.BrickColor = originalBrickColor
			end
			local originalMaterialVariant = part:GetAttribute("OriginalMaterialVariant")
			if originalMaterialVariant then
				--print("originalMaterialVariant")
				part.MaterialVariant = originalMaterialVariant
			end
		end
	end
	
	for _, part in workspace:WaitForChild("GeneratedRooms"):GetDescendants() do
		if part:IsA("Part") or part:IsA("MeshPart") then
			local originalMaterial = part:GetAttribute("OriginalMaterial")
			if originalMaterial then
				--print("originalMaterial found")
				part.Material = originalMaterial
			end
			local originalBrickColor = part:GetAttribute("OriginalBrickColor")
			if originalBrickColor then
				--print("originalBrickColor")
				part.BrickColor = originalBrickColor
			end
			local originalMaterialVariant = part:GetAttribute("OriginalMaterialVariant")
			if originalMaterialVariant then
				--print("originalMaterialVariant")
				part.MaterialVariant = originalMaterialVariant
			end
		end
	end
end

ToggleLowGraphicsEvent.OnServerEvent:Connect(function(player, enableLowGFX: boolean)
	local currentTime = tick()
	local lastUsageTime = lastUsageTimes[player.UserId] or 0

	if currentTime - lastUsageTime >= CooldownTime then
		lastUsageTimes[player.UserId] = currentTime

		if enableLowGFX then
			setLowGraphics()
		else
			resetGraphics()
		end
	else
		warn(tostring(player.Name) .. " is within the cooldown period.")
	end
end)

Example of the path attribute

  1. What is the issue? Include screenshots / videos if possible!

My issue is that when the getPath() function is ran, it returns a string value pertaining the path to the part itself, when it is in ReplicatedStorage, so it returns nil each time I try to use the getInstanceFromPath() function.
image

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I am wanting to have the OriginalPath attribute’s value not to be set to the instance itself, but the instances parent. I’ve tried to use the AI assistant, but it isn’t too much of help, tried to suggest using the “Path” service provided by Roblox… and I don’t really know where to start with this type of question!

1 Like