Function calling Question

What do I want to achieve?

Well, I want to trigger/call a function when a frame’s visibility is set to False.

Solutions tried so far?

I’ve tried this piece of code it works, but only once. :neutral_face:

-- frame = game.Players.LocalPlayer.PlayerGui.AnimalScreen["10"]
-- function = CompleteScreen(game.Players.LocalPlayer.PlayerGui.AnimalScreen.CompletedScreen)

game.Players.LocalPlayer.PlayerGui.AnimalScreen["10"]:GetPropertyChangedSignal("Visible"):Connect(function()
	CompleteScreen(game.Players.LocalPlayer.PlayerGui.AnimalScreen.CompletedScreen)
end)

What is the function CompleteScreen, what is AnimalScreen, and what does this have to do with a quest? Also, is the visibility going back to true eventually before being set to false again?

This is the piece of code that is the function.
All I want is for this function to run on frames visibility change

Yes.

No, that is calling the function. What’s inside the function?

local function CompleteScreen(Screen)
	local Return_Button = Screen["Return Button"]
	local Play_Button = Screen["Play Button"]
	local Score = Screen.Score

	local R_Color = Color3.fromRGB(226, 65, 65)
	local R_TweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local R_Tween = TweenService:Create(Return_Button, R_TweenInfo, {BackgroundColor3 = R_Color})

	local R_Color = Color3.fromRGB(255, 73, 73)
	local R_TweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local R_LeaveTween = TweenService:Create(Return_Button, R_TweenInfo, {BackgroundColor3 = R_Color})
	
	Return_Button.MouseEnter:Connect(function()
		R_Tween:Play()
		Return_Button.Font = "GothamBold"
	end)
	
	Return_Button.MouseLeave:Connect(function()
		R_LeaveTween:Play()
		Return_Button.Font = "GothamSemibold"
	end)
	
	Return_Button.MouseButton1Click:Connect(function()
		Screen.Parent.Enabled = false
		game.Players.LocalPlayer.PlayerGui["Game UI"].Enabled = true
	end)

I don’t understand why you need what’s inside the function. My problem is with a solution for a function to run on frames visibility change. Are you proposing that there’s an issue inside the function? :thinking:

Could you say what this prints over time?

local player = game.Players.LocalPlayer
local ui = player.PlayerGUi.AnimalScreen

-- Why is it called '10'?
ui["10"]:GetPropertyChangedSignal("Visible"):Connect(function()
    print("visible:",ui["10"].Visible)
	CompleteScreen(ui.CompletedScreen)
    print("Finished complete screen")
end)

It’s the name of the frame. That rhymed! :sunglasses:

Why is the name of the frame ‘10’?

I’ve been making a Q&A game, and that frame is Question 10, hence the name. Is there a problem?

It’s just that maybe you could use a for loop to iterate all the questions so you don’t have to index with a number.

Is this gonna help my situation?

You never know, maybe it will! But anyways, did my script print something? It’s for debugging purposes.

image