Help with ScreenGui not destroying after script is completed

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello fellas, basically I want the screengui created by using the instance to be destroyed after the entire script finishes running, doesn’t seem to be working no matter what I try though, am I missing something?
    It’s supposed to act like a sort of loading screen for each player that joins the game!
local StarterGui = game:FindFirstChild("StarterGui")
local SoundService = game:FindFirstChild("SoundService")
local DoorOpenAndClose = SoundService.Door
local Footsteps = SoundService.Footstep









Here's the script! :

game.Players.PlayerAdded:Connect(function(player)
	print(player.Name.." has joined")
	local BlackScreen = Instance.new("ScreenGui")
	BlackScreen.Enabled = true
	BlackScreen.Parent = StarterGui
    BlackScreen.IgnoreGuiInset = true

    StarterGui:WaitForChild("ScreenGui")
    local BlackScreenFrame = Instance.new("Frame")
	BlackScreenFrame.Size = UDim2.new(0,1378,0,680)
    BlackScreenFrame.Active = true
    BlackScreenFrame.Parent = BlackScreen
    BlackScreenFrame.BackgroundColor3 = Color3.fromHSV(0, 0, 0)
    

    Footsteps:Play()
    Footsteps.Ended:Wait()
	DoorOpenAndClose:Play()
	DoorOpenAndClose.Ended:Wait()
    
    
end)


I appreciate any type of help!

1 Like

I don’t understand. You’re trying to make a locally based instance on the server, the StarterGui is not shared.

Add a LocalScript in your PlayerGui, and replicate this process there minus the PlayerAdded connection.