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)
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.
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
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
Basically, you’re going to want to have two separate ScreenGui Objects, something like this:
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.
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.
I also recommend using :Destroy() and not :Remove() if you do not need your Intro GUI anymore.