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

Problem with parenting a frame to PlayerGui?

Asked by
xAlqhs 0
5 years ago
Edited 5 years ago

My code isn't working for creating a gui when a player joins the server. This script is in StarterGui and is a LocalScript

Code:

local player = game.Players.LocalPlayer

01local ScreenGui = Instance.new("ScreenGui")
02ScreenGui.Parent = player.PlayerGui
03local frame = Instance.new('ImageLabel')
04frame.Parent = player.PlayerGui:WaitForChild("ScreenGui")
05frame.Image = 'rbxassetid://3570695787'
06frame.Size = UDim2.new(0, 228,0, 60)
07frame.ImageColor3 = Color3.fromHSV(85, 170, 255)
08frame.Position = UDim2.new(-1, 0,0.914, 0)
09frame.BackgroundTransparency = 0.7
10 
11local text = Instance.new("TextLabel")
12text.Parent = player.PlayerGui.ScreenGui:WaitForChild("Frame")
13text.Size = UDim2.new(0, 228,0, 60)
14text.Position = UDim2.new(-1, 0,0.914, 0)
15text.BackgroundTransparency = 1
16    wait(1)
17player.Name = text.Text
18frame:TweenPosition(UDim2.new(0.006, 0,0.914, 0), 'Out', 'Sine' )

2 answers

Log in to vote
0
Answered by
pingsock 111
5 years ago
Edited 5 years ago
01game.Players.PlayerAdded:Connect(function(player)
02-- Creating the ScreenGui.
03-- First you must define it (local statement)
04local Example1 = Instance.new("ScreenGui")
05-- When you create a new instance, you can actually parent it whilst doing so, so instead, let's delete this screen gui.
06Example1:Destroy()
07-- Now, let's create one and set the parent along with it.
08local ScreenGui = Instance.new("ScreenGui",player:WaitForChild("PlayerGui"))
09local Frame = Instance.new("ImageLabel",ScreenGui) -- You have just set it's parent to the recent GUI you made.
10Frame.Image = 'rbxassetid://3570695787'
11Frame.Size = UDim2.new(0, 228,0, 60)
12Frame.ImageColor3 = Color3.fromHSV(85, 170, 255)
13Frame.Position = UDim2.new(-1, 0,0.914, 0)
14Frame.BackgroundTransparency = 0.7
15local Text = Instance.new("TextLabel",Frame)
View all 26 lines...
0
Here's what you will create after running my script: https://gyazo.com/506299969d6897e28fd79a76b0bdf342 pingsock 111 — 5y
0
My bad, line 16 should be removed. pingsock 111 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Try this:

01local ScreenGui = Instance.new("ScreenGui")
02ScreenGui.Parent = player.PlayerGui
03local frame = Instance.new('ImageLabel')
04frame.Parent = player.PlayerGui:WaitForChild("ScreenGui")
05frame.Image = 'rbxassetid://3570695787'
06frame.Size = UDim2.new(0, 228,0, 60)
07frame.ImageColor3 = Color3.fromHSV(85, 170, 255)
08frame.Position = UDim2.new(-1, 0,0.914, 0)
09frame.BackgroundTransparency = 0.7
10 
11local text = Instance.new("TextLabel")
12text.Parent = player.PlayerGui.ScreenGui:WaitForChild("ImageLabel")
13text.Size = UDim2.new(0, 228,0, 60)
14text.Position = UDim2.new(-1, 0,0.914, 0)
15text.BackgroundTransparency = 1
16 
17 
18wait(1)

Basically your referencing frame to the variable, and not the instance. Alternatively you could also use text.Parent = player.PlayerGui.ScreenGui:WaitForChild(frame)

A string and a object are different

Answer this question