UI Dark Mode Not working

Hi!
Recently I have been trying to do a Dark Mode. but am failing. Can someone describe these issues?
1: For some reason, not working all together. When activated, it just destroys the settings frame + button. Button:

--5595965685

local btn = script.Parent
local LoadFrame = script.Parent.Parent.Parent.Parent.WarningSettingsDME

LoadFrame.Visible = false

btn.MouseButton1Click:Connect(function()
	if LoadFrame.Visible == false then
		LoadFrame.Visible = true
		LoadFrame.Parent.Parent.Disabled = false
		script.Parent.Image = "rbxassetid://5595965685"
		script.Parent.Parent.TextLabel1.Text = "Disabled! Click to Re enable."
		script.Parent.IfDisabled.Disabled = false
		script.Disabled = true
		
		print "Someone turned on Dark Mode!"
	end

end)

Main DarkMode Script:

while wait (0.1) do
	local t = script.Parent.Parent:GetDescendants()

	for _, instance in pairs(t) do

		if instance:IsA("Frame") then instance.BackgroundColor3 = Color3.fromRGB(42, 42, 42) end

		if instance:IsA("TextLabel") then instance.TextColor3 = Color3.fromRGB(255,255,255) end

	end

end

2: How would I use DataStore to find if the player had it enabled. Adn if enabled, enable the script. If not, keep it disabled until they change it via settings.

Update: Only the first part of 1 is not working.

Could you please provide an explorer view? Also, for the DataStore, just save a BoolValue to see if they have Dark Mode on or not.

just to point out: it probably is working, you just forgot to put parentheses around your printScreen Shot 2021-04-08 at 6.00.39 PM
it should be:
print("Someone turned on Dark Mode!")

print “test” works, i personally only use print (“test”) when I’m doing something like:

print ("Could not load, at attempt #"..attempt.."! Error is printed below. Retrying..")
warn (error)
loadGame()

Personally I wouldn’t recommend encasing a loop while attempting to detect changes by every frame, just use the GetPropertyChangedSignal instead for the LoadFrame variable

@IceTheOneAndOnly Surprisingly enough, that works with or without parentheses

Can you check if there are any other scripts that could be destroying the Frame + Button?

1 Like

I stated that above.
image
image

Okay but back on topic

Could it be that you’re destroying the Frame/Button on a different script upon activation? Either that or you’re making the Frames invisible

Your disabling the script before it can print anything

I don’t know… Can’t find it nopw because of this aggressive message below

(of course, my ui designer is obsessed with me touching NOTHING UI related, and he deleted it. (if your reading this madden, WHY… I SPENT SOME TIME ON THAT >:((( )

This line might be the problem. The frame with the button is being disabled when the script runs, and then when the button is pressed it is enabled again however the button cant be pressed when it is disabled, unless there is another script enabling the frame.

Also, it seems script.Parent is used 4 times in the script, but there is already a ‘btn’ variable for it. Rather than using script.Parent every time, it would be more efficient and easier to read if the variable was used instead.