ImageTransparency won't work in game but works in Studio

Hello, developers. I am making settings for my game, and I made it so they save. There is nothing wrong with the writing, or reading to the datastore. The problem is when it gathers the settings in the datastore stored as strings and enables them, they won’t enable. Clicking the settings works perfectly fine, but loading them in doesn’t. I’ve printed out the ImageTransparency of the checkbox, which prints 0 (visible) but every single time it’s invisible. I’ve ensured no other script is interfering with it, and I even made a loop so it is enabled and disabled. I’ve printed everything you can think of; enabled or disabled, transparency, setting name, and button. It just won’t work. It says the setting IS ON when I print it, but it is not on.

It also doesn’t help that this only occurs when I’m in the game and not Studio, so I can’t check the ImageTransparency property. I have to print it.

I honestly think this is an engine bug, but I really don’t know. Please help me, I am desperate!

(The print(“SHOWING IT OMGGGGGGGGGGG”) prints btw.)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WriteDatastoreRemote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("WriteDatastore")
local SettingsLoadedRemote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("SettingsLoaded")
local Players = game:GetService("Players")

local settingsFrame = script.Parent
local ScrollingFrame = settingsFrame:WaitForChild("ScrollingFrame")

local ROBLOXMS = require(ReplicatedStorage:WaitForChild("ROBLOXMS"))

local Frames = {}
local LoadingSettings = true

function ToggleButton(Button: ImageButton, Frame: Frame)
	Frames[Frame.Name].Toggled = not Frames[Frame.Name].Toggled

	local Toggled = Frames[Frame.Name].Toggled
	print(Toggled)

	if Toggled then
		Button.ImageTransparency = 0
		print("SHOWING IT OMGGGGGGGGGGG")
	else
		Button.ImageTransparency = 1
	end
end

function WriteToDatastore(Toggled, Setting)
	WriteDatastoreRemote:FireServer(Setting, Toggled)
end

function LoadSettings(Settings: {string})
	repeat task.wait() until Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("LoadingFrame"):GetAttribute("Complete")
	task.wait(0.5)
	print("TRIGGERING")
	
	for _,Setting in ipairs(Settings) do
		print(Frames[Setting].Button.Parent.Name)
		task.spawn(function()
			while true do
				task.wait(2)
				Frames[Setting].Triggered(Frames[Setting].Button)
			end
		end)
	end
	
	LoadingSettings = false
end

Frames["DisplayPing"] = {
	Toggled = false,
	Button = nil, -- For loading settings

	Triggered = function(Button: ImageButton) -- So it doesn't write again
		ToggleButton(Button, Button.Parent)
		
		_G.Settings["DisplayPing"](Frames[Button.Parent.Name].Toggled)
		if not LoadingSettings then WriteToDatastore(Frames[Button.Parent.Name].Toggled, Button.Parent.Name) end
	end,
}

Frames["DisplayFPS"] = {
	Toggled = false,
	Button = nil,

	Triggered = function(Button: ImageButton)
		ToggleButton(Button, Button.Parent)

		_G.Settings["DisplayFPS"](Frames[Button.Parent.Name].Toggled)
		if not LoadingSettings then WriteToDatastore(Frames[Button.Parent.Name].Toggled, Button.Parent.Name) end
	end,
}

Frames["LowGraphics"] = {
	Toggled = false,
	Button = nil,

	Triggered = function(Button: ImageButton)
		ToggleButton(Button, Button.Parent)

		_G.Settings["LowGraphics"](Frames[Button.Parent.Name].Toggled)
		if not LoadingSettings then WriteToDatastore(Frames[Button.Parent.Name].Toggled, Button.Parent.Name) end
	end,
}

for _,v in pairs(ScrollingFrame:GetChildren()) do
	if not v:IsA("Frame") then continue end
	local FrameTable = Frames[v.Name]
	
	FrameTable.Button = v.SelectButton
	
	v.SelectButton.MouseButton1Click:Connect(function()
		FrameTable.Triggered(FrameTable.Button)
	end)
end

SettingsLoadedRemote.OnClientEvent:Connect(LoadSettings)
2 Likes

I’ve found something very interesting. I deleted the button, but it’s still there in the UI. However, when I try to print the name of the button it errors because it doesn’t exist, even though it does in the UI!

This is all in the same script, and the checkboxes are the setting buttons.

If nobody responds, I am going to open up a bug report then. I feel like I’m going crazy on this.
Please help. Thanks.

I’ve figured it out. For some reason its using the StarterGui’s GUI instead of the player.

In studio, it runs both the GUI and the player’s scripts. But in the game it only does it about 50% of the time, I don’t know why.

Thanks everyone (nobody) who helped me. This community is really just after getting the most amount of solutions rather than helping. :confused:

1 Like

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