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
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!)