In short
Every property has a type. Text takes a string, Position a Vector3, BrickColor a BrickColor, Material an Enum.Material. The message names the property, the type it wanted and the type you gave it: Unable to assign property Text. string expected, got nil means the value you put into Text was nil. Build the right type (often with .new), or fix the variable that was nil. Property is read only means scripts cannot set that property at all.
What the message means
StarterGui.ScreenGui.Coins.Label:7: Unable to assign property Text. string expected, got nil
Other forms of the same message:
Unable to assign property Position. Vector3 expected, got numberUnable to assign property MoveDirection. Property is read onlyUnable to assign property BrickColor. BrickColor expected, got Color3Unable to assign property Material. Invalid value "Glowing" for enum Material
Roblox converts a few things for you: numbers are accepted where a string is expected, so label.Text = 5 works. Most other mismatches stop the script.
The property name tells you which line part failed even on a long line: it is the one after the dot on the left of =.
Causes and fixes
Four things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
- The value is nil
- A number or the wrong Roblox type was given
- The property is read only
- The text is not a valid enum value
The value is nil
A table entry, attribute or function result that is nil cannot go into a property. UI labels are the usual place: string expected, got nil.
local label = script.Parent
local names = { "Sword", "Bow" }
-- names[3] does not exist:
-- Unable to assign property Text. string expected, got nil
label.Text = names[3]
Use a fallback with or, or skip the assignment when the value is missing.
local label = script.Parent :: TextLabel
local names = { "Sword", "Bow" }
label.Text = names[3] or "Nothing equipped"
A number or the wrong Roblox type was given
Position needs a Vector3, Size on UI needs a UDim2, BrickColor a BrickColor and Color a Color3. Giving numbers or the wrong one of these fails.
local part = workspace:WaitForChild("Platform")
-- Unable to assign property Position. Vector3 expected, got number
part.Position = 10
-- Unable to assign property BrickColor. BrickColor expected, got Color3
part.BrickColor = Color3.new(1, 0, 0)
Build the right type with its constructor, and use Color for Color3 values.
local part = workspace:WaitForChild("Platform") :: BasePart
part.Position = Vector3.new(0, 10, 0)
part.Color = Color3.new(1, 0, 0)
-- or, with a named BrickColor:
part.BrickColor = BrickColor.new("Bright red")
The property is read only
Some properties report what the engine is doing and cannot be set by scripts. Humanoid.MoveDirection is a common one: it shows which way the character is walking, so setting it to make an NPC walk fails.
local npc = workspace:WaitForChild("Guard")
local humanoid = npc:WaitForChild("Humanoid")
-- Unable to assign property MoveDirection. Property is read only
humanoid.MoveDirection = Vector3.new(1, 0, 0)
Use the method that does what you want. A Humanoid walks with Move (a direction) or MoveTo (a point). For your own data, use an attribute or a value object.
local npc = workspace:WaitForChild("Guard")
local humanoid = npc:WaitForChild("Humanoid") :: Humanoid
humanoid:Move(Vector3.new(1, 0, 0))
-- or walk to a point:
humanoid:MoveTo(Vector3.new(20, 0, 0))
The text is not a valid enum value
Enum properties such as Material accept an Enum item, or its exact name as a string. A misspelt name fails with Invalid value "..." for enum Material.
local part = workspace:WaitForChild("Platform")
-- Unable to assign property Material. Invalid value "Glowing" for enum Material
part.Material = "Glowing"
Use the Enum item. The Script Editor completes the names for you, so typos cannot happen.
local part = workspace:WaitForChild("Platform") :: BasePart
part.Material = Enum.Material.Neon
Fix it in your place
Paste the error, RoCode fixes it in your place
Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.
RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.
How to find the line that causes it
- Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
- Find the first red line. It starts with the script's place in the Explorer and the line number, such as
ServerScriptService.Shop:12:. - Click the red line. Studio opens that script with the cursor on the failing line.
- Read the lines between
Stack BeginandStack Endunder it: they list the calls that led there, newest first, so you can see which function called the broken one. - Still not sure which value is wrong? Add
print(typeof(x), x)just above the line, or set a breakpoint on it and read the values in the Watch window.
Questions
What does string expected, got nil mean?
You tried to set a text property, such as Text or Name, to a value that was nil. Find out why the value is missing, or use a fallback: label.Text = value or "".
How do I set a part position from numbers?
Wrap them in a Vector3: part.Position = Vector3.new(x, y, z). For UI, Size and Position take a UDim2.new(...) or UDim2.fromScale(...).
BrickColor or Color?
Color takes a Color3 (any colour, from RGB). BrickColor takes a BrickColor from the named palette. Setting one also changes the other.
Can RoCode fix it?
Yes. Paste the Output line into RoCode. It reads the line in the script in your open place and sets the property with the right type or fixes the nil value.
Sources and further reading
- Roblox Creator Docs: data types. Vector3, UDim2, Color3, BrickColor
- Roblox Creator Docs: enums
- Roblox Creator Docs: attributes
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 23 October 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the message format strings in Roblox Studio itself (macOS build of 13 October 2026) on 23 October 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.