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

local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Parent = player.PlayerGui
local frame = Instance.new('ImageLabel')
frame.Parent = player.PlayerGui:WaitForChild("ScreenGui")
frame.Image = 'rbxassetid://3570695787'
frame.Size = UDim2.new(0, 228,0, 60)
frame.ImageColor3 = Color3.fromHSV(85, 170, 255)
frame.Position = UDim2.new(-1, 0,0.914, 0)
frame.BackgroundTransparency = 0.7

local text = Instance.new("TextLabel")
text.Parent = player.PlayerGui.ScreenGui:WaitForChild("Frame")
text.Size = UDim2.new(0, 228,0, 60)
text.Position = UDim2.new(-1, 0,0.914, 0)
text.BackgroundTransparency = 1
    wait(1)
player.Name = text.Text
frame: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
game.Players.PlayerAdded:Connect(function(player)
-- Creating the ScreenGui.
-- First you must define it (local statement)
local Example1 = Instance.new("ScreenGui")
-- When you create a new instance, you can actually parent it whilst doing so, so instead, let's delete this screen gui.
Example1:Destroy()
-- Now, let's create one and set the parent along with it.
local ScreenGui = Instance.new("ScreenGui",player:WaitForChild("PlayerGui"))
local Frame = Instance.new("ImageLabel",ScreenGui) -- You have just set it's parent to the recent GUI you made.
Frame.Image = 'rbxassetid://3570695787'
Frame.Size = UDim2.new(0, 228,0, 60)
Frame.ImageColor3 = Color3.fromHSV(85, 170, 255)
Frame.Position = UDim2.new(-1, 0,0.914, 0)
Frame.BackgroundTransparency = 0.7
local Text = Instance.new("TextLabel",Frame)
-- Ignore that comment about line 16, its replaced with this comment.
Text.Size = UDim2.new(0, 228,0, 60)
Text.Position = UDim2.new(-1, 0,0.914, 0)
Text.BackgroundTransparency = 1
wait(1) -- Why wait?
-- One mistake, you have attempted to change the player's name to the given text on the TextLabel, consider turning this around.
Text.Text = player.Name
-- Connecting the PlayerAdded function and "end)"ing it isn't necessary if you have done something like that already.
end)

-- This script should function properly, your welcome :)
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:


local ScreenGui = Instance.new("ScreenGui") ScreenGui.Parent = player.PlayerGui local frame = Instance.new('ImageLabel') frame.Parent = player.PlayerGui:WaitForChild("ScreenGui") frame.Image = 'rbxassetid://3570695787' frame.Size = UDim2.new(0, 228,0, 60) frame.ImageColor3 = Color3.fromHSV(85, 170, 255) frame.Position = UDim2.new(-1, 0,0.914, 0) frame.BackgroundTransparency = 0.7 local text = Instance.new("TextLabel") text.Parent = player.PlayerGui.ScreenGui:WaitForChild("ImageLabel") text.Size = UDim2.new(0, 228,0, 60) text.Position = UDim2.new(-1, 0,0.914, 0) text.BackgroundTransparency = 1 wait(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