Attempt to get length of a nil value?

Hello there developers! I have an obstacle and I need to rely on you guys for some help. You see, I have a script where you interact with a proximity prompt and it gives dialogue. However, I see to be getting a weird error which says attempt to get length of a nil value and I’m not sure why. If you guys could tell me what’s wrong, it would be much appreciated. Thank you!

Script From Prompt:

script.Parent.robothelpprompt.Triggered:Connect(function(player)
	script.Parent.robothelpprompt.Enabled = false
	local text = "WHAT SHALL I ASSIST WITH?"
	local rs = game:GetService("ReplicatedStorage")
	rs.Robotinteract:FireAllClients()
	rs.Robotinteract:FireClient(player,"EXPERIMENT 404",text,"0, 0.00784314, 0.505882")
end)

Local Script For DIalogue Frame:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local scriptParent = script.Parent

local function soundPlay()
	local sound = script["dialog beep"]:Clone()
	sound.Parent = scriptParent
	sound.Name = "dialog"
	sound:Play()

	wait(1)

	sound:Remove()
end

-- event
ReplicatedStorage.Robotinteract.OnClientEvent:Connect(function(name, text, color)
	scriptParent.Visible = true

	scriptParent.npcName.Text = "EXPERIMENT 404"
	scriptParent.npcName.TextColor3 = Color3.new(0, 0.00784314, 0.505882)

	for i = 1, #text do -- heres the error
		scriptParent.npcText.Text = string.sub(text,1,i)
		coroutine.wrap(soundPlay)()
		wait(0.04)
	end

	wait(1.75)
	
	script.Parent.Wage.Visible = true
	script.Parent.Israel.Visible = true
	script.Parent["Job History"].Visible = true
end)

What line number is the error on?
There should be more information in the Output about which script and which line is the issue.

You are trying to get the length of text in the client event

text is nil so it errors

line 22 of the local script pretty sure I put a note there

1 Like

I see. So in that case, any solution for that?

You are firing the event twice

One of them fires for one player and that one works

The other one fires for everyone but you didn’t give any parameters so it errors

This script fires for everyone with the correct parameters

script.Parent.robothelpprompt.Triggered:Connect(function(player)
	script.Parent.robothelpprompt.Enabled = false
	local text = "WHAT SHALL I ASSIST WITH?"
	local rs = game:GetService("ReplicatedStorage")
	rs.Robotinteract:FireAllClients("EXPERIMENT 404",text,"0, 0.00784314, 0.505882")
end)
2 Likes

Alright got it. Thank you for the help!

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