Help with a set time command

So I’m working on making chat commands that are like minecraft’s chat commands, I’m working on the time set command, but I got an error: ServerScriptService.Commands:24: attempt to call a nil value.

Line 24 of the script:

if Msg:Sub(1,10) == Prefix..'time set ' or Msg:Sub(1,10) == Prefix..'Time set ' or Msg:Sub(1,10) == Prefix..'Time Set ' then
Full Code
--// Services \\--
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local ServerScriptService = game:GetService("ServerScriptService")

--// Global Variables \\--



--// Settings \\--

local Prefix = '/'

local Admins = {
	['foodislife345678'] = 'Owner';
}

--// Commands \\--

Players.PlayerAdded:Connect(function(Player)
	if Admins[Player.Name] then
		print('Admin '..Player.Name..' has joined!')
		Player.Chatted:Connect(function(Msg)
			if Msg:Sub(1,10) == Prefix..'time set ' or Msg:Sub(1,10) == Prefix..'Time set ' or Msg:Sub(1,10) == Prefix..'Time Set ' then
				local Number = Msg:Sub(11)
				Lighting.ClockTime = Number
				if Number == 'day' or Number == 'Day' then
					Lighting.ClockTime = 14
				end
				if Number == 'night' or Number == 'Night' then
					Lighting.ClockTime = 0
				end
			end
		end)
	end
end)

I don’t know what the problem is here so if you can tell me what it is and how to fix it then I would greatly appreciate that!

– food

Lua(u) is case sensitive, so you’ll have to do sub, not Sub.

Also it looks like you want to remove case sensitivity from the string, so just lower it then just compare it to a lowercased string, since you are lowercasing the input anyway it doesn’t matter what casing a player uses.

if Msg:lower():sub(1,10) == Prefix..'time set ' then
1 Like