How can i make the Instance.new screengui appear straight away instead of after the player has respawned

So i want the GUI to appear straight away after the player has leveled up instead of respawn, but idk how to do this

local screengui = Instance.new("ScreenGui",game:GetService("StarterGui"))
local frame = Instance.new("Frame",screengui)
screengui.Parent = game.StarterGui
screengui.Name = "ExampleGUI"
screengui.Enabled = true
frame.Name = "ExampleFrame"
frame.Size = UDim2.new(0.5,0,0.5,0)
frame.Position = UDim2.new(0.25,0,0.25,0)
wait(3)
screengui.Enabled = false
2 Likes

In

local screengui = Instance.new("ScreenGui",game:GetService("StarterGui")), instead of doing game:GetService("StarterGui"), do game.Players.LocalPlayer.PlayerGui.

The reason for this is because StarterGui is the thing that replicates to clients when they join the game/respawn, but playergui is the thing that is actively showing everything in it.

local screengui = Instance.new(“ScreenGui”,game.Players.LocalPlayer.PlayerGui)

like this right, i tried and it does not work.

1 Like

Is this a local script or a server script?
Edit: Nevermind, I see the problem.

local screengui = Instance.new("ScreenGui",game.Players.LocalPlayer.PlayerGui) -- You are setting the parent to playergui.
local frame = Instance.new("Frame",screengui)
screengui.Parent = game.StarterGui -- Then you're setting the parent to StarterGui.
screengui.Name = "ExampleGUI"
screengui.Enabled = true
frame.Name = "ExampleFrame"
frame.Size = UDim2.new(0.5,0,0.5,0)
frame.Position = UDim2.new(0.25,0,0.25,0)
wait(3)
screengui.Enabled = false

So simply remove this line: screengui.Parent = game.StarterGui, and it will work.

1 Like

its in a server script, i get the error attempet to index field localplayer (a nil value)

UI design should be generally made and controlled by the client. Put the code in a local script and it will work.

If you need the GUI to appear during specific moments (like levelling up), you need to use remote events. You can read about them here: RemoteEvent | Documentation - Roblox Creator Hub

How would i do this?, i am not using a click gui or button so i cant use Mouseclick1 and i dont know what to put.

local screengui = Instance.new("ScreenGui", game.Players.PLAYERNAME.PlayerGui)
local frame = Instance.new("Frame",screengui)
screengui.Name = "ExampleGUI"
screengui.Enabled = true
frame.Name = "ExampleFrame"
frame.Size = UDim2.new(0.5,0,0.5,0)
frame.Position = UDim2.new(0.25,0,0.25,0)
wait(3)
screengui.Enabled = false

This should work.

4 Likes

why would you disable it after 3 Seconds?

So it goes away, but i changed that to destroy instead.

Oops, Didn’t read it fully, my bad.