How do i check if a gui becomes visible while player is playing?

im trying to make a loading screen but i want to pause the main music while its going on. im checking to see if it becomes visible since when they press “start” it starts the loading sequence.

script:

local maintheme = game.SoundService:WaitForChild("FNAF Ultimate Custom Night Theme")

if script.Parent.Visible then

maintheme.Volume = 0

wait(3)

maintheme.Volume = 0.5

end

what happens is the script only works if i made it visible before pressing start. i want it so the script plays when it becomes visible.

i tryed using .changed but that doesn’t work

1 Like

Have you tried using GetPropertyChangedSignal to create an event listening for the Visible property, bound to a function to do this? Alternatively, wherever in your code is changing whether it’s visible or not, could it not do this functionality too?

1 Like

im not aware of this feature. can you give me an example using the visible property? (Yes i see the post and its example but this would explain more to me)

function visibilityChanged(value) --true or false
	if value then 
		maintheme.Volume = 0
		task.wait(3)
		maintheme.Volume = 0.5
	end
end

local UIObject = script.Parent 

visibilityChanged(UIObject.Visible)
UIObject:GetPropertyChangedSignal("Visible"):Connect(function()
	visibilityChanged(UIObject.Visible)
end)
1 Like

i updated the script to this but its erroring

local maintheme = game.SoundService:WaitForChild(“FNAF Ultimate Custom Night Theme”)
function visibilityChanged(true) --true or false
if true then
maintheme.Volume = 0
task.wait(3)
maintheme.Volume = 0.5
end
end

local UIObject = script.Parent

visibilityChanged(UIObject.Visible)
UIObject:GetPropertyChangedSignal(“Visible”):Connect(function()
visibilityChanged(UIObject.Visible)
end)
error: expect identifier got “true”

change this variable’s name, naming it “true” will cause errors. (when they said “true or false”, they meant the variable would be a true or false)

true or false is the value of the variable named value, it can either be equal to true or false although the variable should stay as it is(value).

script.Parent.Changed:Connect(function()
local s,f = (script.Parent.Visible == true then pcall(function() maintheme.Volume = 0 end) or pcall(function() maintheme.Volume = 0.5 maintheme:Play() end))
if f then
warn(f)
end
end)

If you’re playing the main music on the server, then just make its volume 0 as soon as the player joins in a LocalScript, then after the loading screen has finished loading, play it back up.

1 Like

The same issue works with the loading screen script as well since i used .change; its just not as noticable.