Quest system bit laggy

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

  1. What do you want to achieve?
    Im trying to achieve a working quest system

  2. What is the issue?

The code im using is a constant loop i want to make it so it doesn’t lag

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    Havent found a solution yet
local Module  = require(game.ReplicatedStorage.Quest)
local plr  = game.Players.LocalPlayer
while task.wait(0.1) do
	for i,v in pairs(script.Parent:GetChildren()) do
		if v.ClassName == "Frame" then
			if plr.Quests[v.Namet.Text].Completed.Value == false then
				if v.Rarity.Text == "Easy"  then
					v.LayoutOrder = 1
				end
				if v.Rarity.Text == "Medium"  then
					v.LayoutOrder = 2
				end
				if v.Rarity.Text == "Hard"  then
					v.LayoutOrder = 3
				end
				if v.Rarity.Text == "Insane"  then
					v.LayoutOrder = 4
				end
			else
				v.LayoutOrder = 5
			end
		end
	end
end

move the code inside your loop into a function

the order only has to be set one time when all the quests load, so you could wait and then run it or maybe a safer way is to call it each time something gets added to the quest list

local function updateOrder()
  for i,v in pairs(script.Parent:GetChildren()) do
		if v.ClassName == "Frame" then
			if plr.Quests[v.Namet.Text].Completed.Value == false then
				if v.Rarity.Text == "Easy"  then
					v.LayoutOrder = 1
				end
				if v.Rarity.Text == "Medium"  then
					v.LayoutOrder = 2
				end
				if v.Rarity.Text == "Hard"  then
					v.LayoutOrder = 3
				end
				if v.Rarity.Text == "Insane"  then
					v.LayoutOrder = 4
				end
			else
				v.LayoutOrder = 5
			end
		end
	end
end

--when a quest gets added run the reorder function
script.Parent.ChildAdded:Connect(updateOrder)
1 Like
local orders = {
   ['Easy'] = 1,
   ['Medium'] = 2,
   ['Hard'] = 3,
   ['Insane'] = 4
}

for i,v in pairs(script.Parent:GetChildren()) do
		if v.ClassName == "Frame" then
			if plr.Quests[v.Namet.Text].Completed.Value == false then
				local layoutOrder = orders[v.Rarity.Text] or 5
                v.LayoutOrder = layoutOrder
			end
		end
	end

this isn’t a fix, but something to make your code a lot more readable

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.