Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I tried to instance a frame but it doesn't showed up in the screen? Please help

Asked by 6 years ago

I tried to instance a frame in a local script but it doesn't work. Can someone help me fix this error,

wait()
local startergui = game:GetService("StarterGui")

if startergui then
local screengui = Instance.new("ScreenGui", startergui)
local frame = Instance.new("Frame", screengui)

 if screengui and frame then
    frame.Visible = true
    frame.BackgroundTransparency = 0.3
    frame.BackgroundColor3 = Color3.fromRGB({12,40,14})
    frame.Position = UDim2.new({0, 0, 0, 32})
    frame.Size = UDim2.new({0, 100, 0, 100})
    wait()
 end
end
0
Have you tried resetting the character. NotInventedHere 158 — 6y

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago

The problem is that you are instantiating the frame inside of StarterGui and not PlayerGui. There is a distinct difference between the two objects. StarterGui acts as a template and is not actually what is seen on screen. Every time a player joins, content from the StarterGui is cloned and parented to the player's individual PlayerGui. Each player has their own PlayerGui and that is what's actually seen on screen. In order to fix your problem, simply parent the frame to the PlayerGui instead of StarterGui. PlayerGui can be accessed by doing game.Players.LocalPlayer.PlayerGui.

local playergui = game.Players.LocalPlayer.PlayerGui
local screengui = Instance.new("ScreenGui")
local frame = Instance.new("Frame")
frame.BackgroundTransparency = 0.3
frame.BackgroundColor3 = Color3.fromRGB(12 , 40 , 14)
frame.Position = UDim2.new(0 , 0 , 0 , 32)
frame.Size = UDim2.new(0 , 100 , 0 , 100)

frame.Parent = screengui
screengui.Parent = playergui

(Don't use the second parameter of Instance.new(). It can cause performance issues!)

0
Thank you!! justin12343434 4 — 6y
Ad

Answer this question