I was testing my notification module when I received an error “Attempt to index nil with WaitForChild”
The error occurs on line 5
Can anyone fix this! Thanks
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui",4)
local Notifications = PlayerGui:WaitForChild("Notifications")
local Container = Notifications:WaitForChild("Container")
local SFX = ReplicatedStorage:WaitForChild("SFX")
local Template = script:WaitForChild("NotifTemplate")
local SoundEffect = SFX:WaitForChild("Notify")
local ORIGINAL_SIZE = Template.Size
local NotificationService = {}
function NotificationService:Notify(TopText: string, BottomText: string, IconId: string, Duration: number)
local newNotification = Template:Clone()
newNotification.Size = UDim2.fromScale(0,0)
newNotification.BackgroundTransparency = 1
newNotification.TopText.Transparency = 1
newNotification.BottomText.Transparency = 1
newNotification.Icon.Transparency = 1
newNotification.TopText.Text = TopText
newNotification.BottomText.Text = BottomText
newNotification.Icon.Image = IconId
newNotification.Parent = Container
TweenService:Create(newNotification, TweenInfo.new(0.3), {BackgroundTransparency = 0}):Play()
TweenService:Create(newNotification.TopText, TweenInfo.new(0.3), {TextTransparency = 0}):Play()
TweenService:Create(newNotification.BottomText, TweenInfo.new(0.3), {TextTransparency = 0}):Play()
TweenService:Create(newNotification.Icon, TweenInfo.new(0.3), {ImageTransparency = 0}):Play()
TweenService:Create(newNotification, TweenInfo.new(.8, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Size = ORIGINAL_SIZE}):Play()
SoundEffect:Play()
task.wait(Duration)
TweenService:Create(newNotification, TweenInfo.new(0.2), {BackgroundTransparency = 1}):Play()
TweenService:Create(newNotification.TopText, TweenInfo.new(0.3), {TextTransparency = 1}):Play()
TweenService:Create(newNotification.BottomText, TweenInfo.new(0.3), {TextTransparency = 1}):Play()
TweenService:Create(newNotification.Icon, TweenInfo.new(0.3), {ImageTransparency = 1}):Play()
TweenService:Create(newNotification, TweenInfo.new(.8, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out), {Size = UDim2.fromScale(0,0)}):Play()