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

Why is this ChildAdded Event not Working?

Asked by
Hypgnosis 186
4 years ago
Edited 4 years ago

I'm making a custom Leaderboard GUI. ChildAdded event is not firing. Output reads 1. Neither 2 or 3 appear.

local Player = game:GetService('Players').LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')

local Frame = PlayerGui.Leaderboard.Frame


print(1)
local function IncreaseFrame()
    print(2)
    if Frame.Size.Y.Offset < 245 then
        print(3)
        Frame.Size.Y.Offset = Frame.Size.Y.Offset + 20
    end
end


Frame.ChildAdded:Connect(IncreaseFrame)

Here is the code which adds a TextLabel to Frame on player join (same script):

local TL = Instance.new('TextLabel')
TL.Name = Player.Name
TL.Text = Player.Name
TL.AnchorPoint = Vector2.new(0.5,0)
TL.Position = Frame.User.Position
TL.Size = Frame.User.Size
TL.TextSize = 16
TL.TextStrokeTransparency = 0.5
TL.Font = Enum.Font.GothamSemibold
TL.BackgroundTransparency = 1
TL.TextColor3 = Color3.fromRGB(255,255,255)
TL.TextXAlignment = Enum.TextXAlignment.Left

TL.Parent = Frame -- THIS SHOULD FIRE CHILDADDED

0
Are these in the same script? Im Just wondering because In the second Block of code I what is the definition of frame variable? JoshChubi 74 — 4y
0
Yes, same LocalScript. TL.Parent = Frame is referring to the same Frame variable in the first code block. Hypgnosis 186 — 4y
0
Do you ever change the Frame variable anywhere else in the script, like referencing another frame with same variable? Because it should work. :/ JoshChubi 74 — 4y
0
you can check by changing last line to TL.Parent = PlayerGui.Leaderboard.Frame, and if it works then you are changing the Frame variable somewhere else JoshChubi 74 — 4y
0
Maybe the text label is being added before child added event listener could be established? programmerHere 371 — 4y

Answer this question