Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"attempt to get length of field 'Value' (a number value)" error?

I'm making a code input GUI to open a door, but when I try to calculate the string of the input value (to check if it's 4 or more characters), it gives me the error

16:42:58.732 - Players.Player1.PlayerGui.ScreenGui.Frame.Script:35: attempt to get length of field 'Value' (a number value)
16:42:58.733 - Stack Begin
16:42:58.735 - Script 'Players.Player1.PlayerGui.ScreenGui.Frame.Script', Line 35
16:42:58.736 - Stack End

My code is:

local input = script.Parent.Input

Input.Changed:connect(function()
	if #Input.Value >= 4 then
		canAddCode = false
		if Input.Value == script.Parent.Code.Value then
			script.Parent.Status.BackgroundColor3 = Color3.new(0, 1, 0)
			script.Parent.Parent:Destroy()
			workspace.DeskDoorA.Model.Model.ErrorMsg.BrickColor = BrickColor.new(BrickColor.Green()())
		else
			script.Parent.Status.BackgroundColor3 = Color3.new(1, 0, 0)
			workspace.DeskDoorA.Model.Model.ErrorMsg.BrickColor = BrickColor.new(BrickColor.Red())
		end
	end
end)

And the full code is

local canAddCode = true
local input = script.Parent.Input
script.Parent.A1.MouseButton1Click:connect(function()
	input.Value = input.Value.."1"
end)
script.Parent.A2.MouseButton1Click:connect(function()
	input.Value = input.Value.."2"
end)
script.Parent.A3.MouseButton1Click:connect(function()
	input.Value = input.Value.."3"
end)
script.Parent.A4.MouseButton1Click:connect(function()
	input.Value = input.Value.."4"
end)
script.Parent.A5.MouseButton1Click:connect(function()
	input.Value = input.Value.."5"
end)
script.Parent.A6.MouseButton1Click:connect(function()
	input.Value = input.Value.."6"
end)
script.Parent.A7.MouseButton1Click:connect(function()
	input.Value = input.Value.."7"
end)
script.Parent.A8.MouseButton1Click:connect(function()
	input.Value = input.Value.."8"
end)
script.Parent.A9.MouseButton1Click:connect(function()
	input.Value = input.Value.."9"
end)
script.Parent.Clear.MouseButton1Click:connect(function()
	input.Value = ""
end)

script.Parent.Input.Changed:connect(function()
	if #script.Parent.Input.Value >= 4 then
		canAddCode = false
		if script.Parent.Input.Value == script.Parent.Code.Value then
			script.Parent.Status.BackgroundColor3 = Color3.new(0, 1, 0)
			script.Parent.Parent:Destroy()
			workspace.DeskDoorA.Model.Model.ErrorMsg.BrickColor = BrickColor.new(BrickColor.Green()())
		else
			script.Parent.Status.BackgroundColor3 = Color3.new(1, 0, 0)
			workspace.DeskDoorA.Model.Model.ErrorMsg.BrickColor = BrickColor.new(BrickColor.Red())
		end
	end
end)

1 answer

✓ Accepted answer

sorry for my last answer, disregard it. I am just not use to using #. we can do istostring() which converts anything to a string.

local input = script.Parent.Input

Input.Changed:connect(function()
    if #tostring(Input.Value) >= 4 then
        canAddCode = false
        if Input.Value == script.Parent.Code.Value then
            script.Parent.Status.BackgroundColor3 = Color3.new(0, 1, 0)
            script.Parent.Parent:Destroy()
            workspace.DeskDoorA.Model.Model.ErrorMsg.BrickColor = BrickColor.new(BrickColor.Green())
        else
            script.Parent.Status.BackgroundColor3 = Color3.new(1, 0, 0)
            workspace.DeskDoorA.Model.Model.ErrorMsg.BrickColor = BrickColor.new(BrickColor.Red())
        end
    end
end)

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.