Wait() completely stops script

Hello, I am trying to make a fade in for a gui, I’ve done these before and they are pretty simple. However, this time, whenever there is wait() in the script, the script just stops. It’s waiting, but infinitely. I’ve never had an issue like this where the wait() stops the entire script forever. I know it’s the wait as I’ve used debugs with print commands and I’ve removed the wait to make it work, although that just makes it pop in and not fade in, not what I’m looking for. This script is the exact same script I always use, so it’s odd that it’s not working here. Also before anyone asks, no, there is nothing in the console to help fix this.

Anyways, here is a bit of the script:

remoteEvents.PlayerLeftCave.OnServerEvent:Connect(function(player)
	
	player.PlayerGui.LocalScript.Disabled = true
	
	local gameover = player.PlayerGui.YouLeft
	
	for i = 0,24,1 do
				
				wait(0.041666) --it breaks here.

				gameover.Frame.Transparency = gameover.Frame.Transparency - 0.041666
				
	end

Thanks in advance if anyone can help me out!

Why are you using a remote event for this. That is the issue. StarterGui contents are locally cloned into PlayerGui, so the server won’t see it. Why is the server manipulating UI in the first place if only one player will see the change? That defeat the purpose of a server.

2 Likes

It may be a little more advanced however I would use the TweenService (https://developer.roblox.com/en-us/api-reference/class/TweenService) for tweening the frame transparency

I also believe that your issue is Transparency isn’t a property for a frame (if gameover.Frame is one), it would be BackgroundTransparency instead

Example use of the TweenService would be:

local TweenService = game:GetService('TweenService')
local DesiredTransparency = 0
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local Tween = TweenService:Create(gameover.Frame, TweenInfo, {BackgroundTransparency = DesiredTransparency})

Tween:Play()

Hope this helps :slight_smile:

2 Likes