Problem Of loading screen

Hello, I made a script that should normally not display two Gui when a user dies or resets except that the script does not take effect. How can I fix this? Here’s the script below, knowing that I’ve dragged the script into ServerScriptService and made it a local script
local Players = game:GetService(“Players”)

local function onPlayerAdded(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild(“Humanoid”)
humanoid.Died:Connect(function()
local starterGui = player:WaitForChild(“PlayerGui”):WaitForChild(“StarterGui”)

        local loadingGui1 = starterGui:FindFirstChild("Loading_Gui"):FindFirstChild("Non-Transparent"):FindFirstChild("Loading")
        if loadingGui1 then
            loadingGui1:Remove()
        end
        
        local loadingGui2 = starterGui:FindFirstChild("Loading_Gui"):FindFirstChild("Transparent"):FindFirstChild("Loading_Gui")
        if loadingGui2 then
            loadingGui2:Remove()
        end
    end)
end)

end

Players.PlayerAdded:Connect(onPlayerAdded)

3 Likes

so what exactly do you want your script to do, could you please word it better?

2 Likes

from what i understood you want two screen Gui to appear whenever a player dies?

2 Likes

No, I don’t want the Gui to appear when the player dies because when you arrive on my game there’s a loading gui that appears. Well, I’d like it to appear just once, not when the player dies and this one appears.

2 Likes

I’m sorry i cant understand what you’re asking for

2 Likes

i’m going to repeat, i created a loading screen gui at the very beginning of my game and i don’t want it to appear every time a player dies on my game and i’d like it to appear just once when the player joins the server for the first time

3 Likes

You are calling a function whenever a Humanoid dies, perhaps that’s the issue. If you want the loading UI to only appear once you can just set its default visibility to true and then set it to false

3 Likes

On your ScreenGui you need to ensure that the ResetOnSpawn property is disabled.

Image:
image

It should be located at the top of your ScreenGui’s properties.

EDIT: Then you don’t need a script to remove it every time the player dies.

1 Like

Basically, you’re going to want to have two separate ScreenGui Objects, something like this:
image

Next, you’ll want to set the “Intro” ScreenGui’s “ResetOnSpawn” property to false, as once you join into the game, your script should’ve already gotten rid of the UI once it completes it’s cycle, and also because you do not want this appearing once the player is finished resetting.
image

Lastly, for your death screen, make sure that It’s not appearing upon the player joining the game, but rather only show up when the player dies, if that’s all working perfectly fine, you’ll want to go into the properties of your death GUI, and essentially do the same as the previous step, but this time, make sure that “ResetOnSpawn” is set to true.

image

I also recommend using :Destroy() and not :Remove() if you do not need your Intro GUI anymore.

1 Like

Why did you censor out part and ui names, what are you trying to hide lol?

1 Like

because anything else that is inside of my game is not relevant, and I do not want to confuse anyone.

And cause I was already working on something.

1 Like