GUI won't enable even though Enabled is set to true

For some reason, this script:

local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local roundEnd = ReplicatedStorage:WaitForChild("RoundEnd")
local WinGUI = player.PlayerGui:WaitForChild("WinGUI")
local WinGUIframe = WinGUI.WG_Frame

coroutine.wrap(function()
	roundEnd.OnClientEvent:Connect(function()
		wait(6.5)
		WinGUI.Enabled = true
		WinGUIframe.Visible = true
		wait(10)
		WinGUI.Enabled = false
		WinGUIframe.Visible = false
	end)
end)()

Refuses to make a GUI show up. I even put a print after the WinGUI.Enabled and it’s being set to true. Is this a bug, or something that I’m doing wrong? (This is in a LocalScript located in StarterPlayerScripts)

Are you meaning to strictly have it so WinGUI is a child of the actual gui object? If not then try checking/setting the actual GUI’s Enabled property.

I don’t know what you mean… WinGUI is a ScreenGui located in StarterGui, and so it’s copied over to PlayerGui. Also, setting a Gui’s Enabled value to true mostly works and only seems to break sometimes. Also, I am not getting an error from anywhere in this.

I used a print to check, and it is changing.

Btw, events run in coroutines anyway. You don’t need that coroutine there. It’s useless.

2 Likes

Sry, I misread your code. My bad.

I have other events that are meant to run at the same time as this one in the same script, does that change the need for a coroutine?

No code runs at the same time. Not right now, you can’t have two pieces of code running at the exact same time. What happens is that when your code yields, (waits etc) other scripts/coroutines will start running their code.

Coroutines are basically the same as creating another script, expect creating another script is slower and less convenient.

So, is the coroutine function still useless?

Yes. It should be for this use.

You shoudn’t use a coroutine unless the code inside this coroutine might yield. Aka has Async, uses wait(), etc.

Since the function you connect to a event is already ‘coroutined’, it is just plain slower.

1 Like

Ok. Still haven’t found the solution to the original problem though. :neutral_face:

Turns out I had ResetOnSpawn set to true… And I kill players to get back to the lobby… :man_facepalming:

1 Like