Script is making gui flicker

Im trying to make a forsaken like game, and the gui is flickering

Gui is flickering, i think its switching between thinking that the nametag is correct and thinking that it isnt, there isnt any elses causing this either.

local character = game.Players.LocalPlayer.Character
while true do
	wait(0.1)
	local nametag = character:FindFirstChild("mynameis")
	if nametag then
		if nametag.Value == "MLG" then
			if script.Parent.Enabled == false then
				script.Parent.Enabled = true
				for none, part in script.Parent:GetDescendants()  do
					if part:IsA("Script") or part:IsA("LocalScript") then
						part.Enabled = true
					end
				end
			else
				for none, part in script.Parent:GetDescendants()  do
					if part:IsA("Script") or part:IsA("LocalScript") then
						part.Enabled = false
					end
				end
				script.Parent.Enabled = false
			end
			end
	else
		script.Parent.Enabled = false
		for none, part in script.Parent:GetDescendants()  do
			if part:IsA("Script") or part:IsA("LocalScript") then
				part.Enabled = false
			end
		end
	end
end

This bit of the code is problematic:

if script.Parent.Enabled == false then
	script.Parent.Enabled = true
	for none, part in script.Parent:GetDescendants()  do
		if part:IsA("Script") or part:IsA("LocalScript") then
			part.Enabled = true
		end
	end
else
	for none, part in script.Parent:GetDescendants()  do
		if part:IsA("Script") or part:IsA("LocalScript") then
			part.Enabled = false
		end
	end
	script.Parent.Enabled = false
end

It’s constantly switching between script.Parent.Enabled == true and script.Parent.Enabled == false, which in turn toggles the part script.

Can you please clarify on what you are wanting the code to do? You may be better off utilising a connection rather than a loop (or potentially you just are changing / checking the wrong value?

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