Attempt to index nil with 'Day'

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Well… I would like to fix this error.

  2. What is the issue? “Attempt to index nil with ‘day’”, but the problem is that Day is a valid child.
    image
    image

local players = game:GetService("Players")
local player = players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")
local events = replicatedstorage:WaitForChild("Events")

local BG = script.Parent.BG
local List = BG:WaitForChild("List")
local ClockedIn = List:WaitForChild("ClockedIn")
local Schedule = List:WaitForChild("Schedule")

local Date = BG:WaitForChild("Date")
local AssociateName = BG:WaitForChild("AssociateName")

local function SetupPhone()
	if events.GetUser:InvokeServer("isStaff") == true then
		local Schedule = events.GetUser:InvokeServer(player.UserId, "Schedule")
		local dateFormat = "Today is %A, %B %d"
		local date = os.date(dateFormat)
		local weekday = os.date("%A")
		
		--//SetupApp
		AssociateName.Text = "Hey there, "..tostring(player.DisplayName)
		Date.Text = tostring(date)
		
		
		Schedule.Day.Text = tostring(weekday)
		Schedule.Hours.Text = Schedule[weekday]
		Schedule.Rank.Text = tostring(player:GetRoleInGroup(16007840))
	end
end

task.wait()
SetupPhone()

Line 27 is the error.

1 Like

The error means that Schedule is nil, not Day.

You are defining Schedule withiin the SetupPhone function as whatever is returned from the InvokeServer. It appears that the InvokeServer isn’t returning anything, meaning SetupPhone is set to nil.
Consider renaming this:

local Schedule = events.GetUser:InvokeServer(player.UserId, "Schedule")

as

local ScheduleData = events.GetUser:InvokeServer(player.UserId, "Schedule")

Thank you! This was probably the most avoidable error, I didn’t even realize I had 2 things named Schedule. :rofl:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.