Attempt to get length of a number value in a function

I’m having problem with this function giving the error above


local function typeText(label, msg, typeTime, color, strokeColor)
	if color then
		Objective.TextColor3 = color
	end

	if strokeColor then
		Objective.UIStroke.Color = strokeColor
	end

	for i=1, #msg do
		sceneGui.BackFrame[label].Text = string.sub(msg, 1, i)
		wait(typeTime / #msg)
	end
end
1 Like

Could try putting this at the top:

msg = tostring(msg)
1 Like

It then gave me this:

local function typeText(label, msg, typeTime, color, strokeColor)
	if color then
		Objective.TextColor3 = color
	end

	if strokeColor then
		Objective.UIStroke.Color = strokeColor
	end
	
	msg = tostring(msg)
	
	for i=1, #msg do
		sceneGui.BackFrame.Objective[label].Text = string.sub(msg, 1, i)
		wait(typeTime / #msg)
	end
end

image

That just means that msg is a variable reference to a number type value.

The unary length operator which is denoted by the hash key “#” can only be used to ascertain the lengths of strings (number of characters) or size of tables (number of items).

As has been suggested, you can coerce a number value into a string value by passing it as an argument to the tostring() global function.

Regarding your second issue, the frame object named “BackFrame” does not contain a child frame object named “Objective”.

1 Like