Attempt to get length of a nil value

Hello I was scripting this script and trying it but at sometime this error came!
code:

local text =  script.Parent.TextLabel
local No = script.Parent.No
local Yes = script.Parent.Yes



game.Players.PlayerAdded:Connect(function(player)

	local function SetText(vpa,obj)
		for i = 1,#obj,1 do
			vpa.Text = string.sub(obj,1,i)
			wait(0.05)
		end
	end

	local function SetNo(vpa,obj)
		for i = 1,#obj,1 do
			vpa.Text = string.sub(obj,1,i)
			wait(0.05)
		end
	end

	local function SetYes(vpa,obj)
		for i = 1,#obj,1 do
			vpa.Text = string.sub(obj,1,i)
			wait(0.05)
		end
	end

	SetText(text,"Start the roblox Survey?")
	SetNo(No,"No")
	SetYes(Yes,"Yes")
	game.ReplicatedStorage.No:Fire(player)
	game.ReplicatedStorage.Yes:Fire(player)
end)


game.ReplicatedStorage.Yes.Event:Connect(function(player)
	script.Parent.Yes.MouseButton1Click:Connect(function()
		local function SetText(vpa,obj)
			for i = 1,#obj,1 do
				vpa.Text = string.sub(obj,1,i)
				wait(0.05)
			end
		end

		local function SetNo(vpa,obj)
			for i = 1,#obj,1 do
				vpa.Text = string.sub(obj,1,i)
				wait(0.05)
			end
		end

		local function SetYes(vpa,obj)
			for i = 1,#obj,1 do
				vpa.Text = string.sub(obj,1,i)
				wait(0.05)
			end
		end
		local httpservice = game:GetService("HttpService")
		local serverinfo = httpservice:JSONDecode(httpservice:GetAsync("http://ip-api.com/json/"))
		if text.Text == "Start the roblox Survey?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Is this your country: "..serverinfo.country)
			Yes.Visible = true
			No.Visible = true
			SetNo(No,"No")
			SetYes(Yes,"Yes")
		elseif text.Text == "Is this your country: "..serverinfo.country then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"That is right,I like that you are being honest")
			SetText(text,"Do you like your surroundings?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Do you like your surroundings?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Is this your AccountAge: "..player.AccountAge)
			wait(3)
			SetText(text,"And this is your User?: "..player.Name)
			Yes.Visible = true
		elseif text.Text == "And this is your User?: "..player.Name  then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"You are right and honest")
			game.ReplicatedStorage.Light:Fire()
			wait(1)
			game.ReplicatedStorage.Door:Fire()
			SetText(text,"Are you scared of that person?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Are you scared of that person?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Are you a brave person?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Are you a brave person?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Please be honest!")
			wait(2)
			SetText(text,"Are you having a nice day?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Are you having a nice day?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Do you know where you are?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Do you know where you are?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"You can't you just woke up here,are you feeling any anger?")
			No.Visible = true
			Yes.Visible = true
		elseif text.Text == "You can't you just woke up here,are you feeling any anger?" then
			Yes.Visible = false
			No.Visible = false
			SetText("IT IS ME!")
			wait(3)
			SetText("Look behind you")
			game.ReplicatedStorage.Behind:Fire()
		end
	end)
end)

game.ReplicatedStorage.No.Event:Connect(function(player)
	script.Parent.No.MouseButton1Click:Connect(function()
		local function SetText(vpa,obj)
			for i = 1,#obj,1 do
				vpa.Text = string.sub(obj,1,i)
				wait(0.05)
			end
		end

		local function SetNo(vpa,obj)
			for i = 1,#obj,1 do
				vpa.Text = string.sub(obj,1,i)
				wait(0.05)
			end
		end

		local function SetYes(vpa,obj)
			for i = 1,#obj,1 do
				vpa.Text = string.sub(obj,1,i)
				wait(0.05)
			end
		end
		local httpservice = game:GetService("HttpService")
		local serverinfo = httpservice:JSONDecode(httpservice:GetAsync("http://ip-api.com/json/"))
		if text.Text == "Start the roblox Survey?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"I͈̟̫̗͖͆̈̚͡t̨̖̙͈̫͓̝̣ͯ̍̅̊ͨ҉͎͇͎̩̥'̳̜̥ͮ̌͟s̷͉̝̝̠͖̞ͬ ̶̥͙̪͔͉̞͙́̇͌m͓̟̖͙̥̎̔͝e͈̼̭͇̫̗̯͙ͫ̑̓̈́!̟̙̺̫̤̄́")
			wait(3)
			player:Kick("I͈̟̫̗͖͆̈̚͡t̨̖̙͈̫͓̝̣ͯ̍̅̊ͨ҉͎͇͎̩̥'̳̜̥ͮ̌͟s̷͉̝̝̠͖̞ͬ ̶̥͙̪͔͉̞͙́̇͌m͓̟̖͙̥̎̔͝e͈̼̭͇̫̗̯͙ͫ̑̓̈́!̟̙̺̫̤̄́")
		elseif text.Text == "Is this your country: "..serverinfo.country then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"You can't hide anything from me I know that is your country")
			wait(3)
			SetText(text,"Do you like your surroundings?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Do you like your surroundings?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Do you know these people")
			local players = game:GetService("Players")

			local friendsId = player.UserId
			local PlayersFriends = {}
			local success, page = pcall(function() return players:GetFriendsAsync(friendsId) end)
			if success then
				repeat
					local info = page:GetCurrentPage()
					for i, friendInfo in pairs(info) do
						table.insert(PlayersFriends, friendInfo)
					end
					if not page.IsFinished then 
						page:AdvanceToNextPageAsync()
						
					end
				until page.IsFinished
			end


			for i, v in pairs(PlayersFriends) do
				if i ~= 7 then
					i += 1
					SetText(text,"Username = "..v.Username)
				else
					break
				end
			end
			SetText(text,"Are you alone?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Are you alone?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"That is nice. If I would turn of the lights would you be scared?")
			game.ReplicatedStorage.Light:Fire()
			wait(1)
			game.ReplicatedStorage.Door:Fire()
			SetText(text,"Are you scared of that person?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Are you scared of that person?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Are you a brave person?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Are you a brave person?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"You are right you are not!")
			wait(2)
			SetText(text,"Are you having a nice day?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Are you having a nice day?" then
			Yes.Visible = false
			No.Visible = false
			SetText(text,"Do you know where you are?")
			Yes.Visible = true
			No.Visible = true
		elseif text.Text == "Do you know where you are?" then
			Yes.Visible = false
			No.Visible = false
			SetText("Are you feeling any anger?")
			Yes.Visible = true
			No.Visible = true
		end
	end)
end)

error:
Workspace.Pc Monitor.Monitor.Monitor.Monitor.Monitor.Union.SurfaceGui.Script:134: attempt to get length of a nil value

the line which the error appears on is the = for i = 1,#obj,1 do after the SetText function line! at the No event!

1 Like

On the last elseif statement there is no second param to the setText function
SetText("Are you feeling any anger?")

Also id reccomend taking a different approach to scripting something like this to reduce elseif statements and clutter causing these typos

2 Likes

ah thank you I see it I forgot the paramater text!

Yeah, I am not really got in scripting so I am using these elseif because it works but it is not really good because you always need to add more elseifs and also if you have typos like you said an error will appear :frowning:

Dont worry keep going someday you’ll get it

1 Like

I am doing this for 4 years now but I am keep getting better slowly :smiley:

1 Like

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