Unable to cast value to Objectin Roblox Luau: what it means and how to fix it

What it means

A Roblox function needed an Instance (a part, a player, a GUI object) and received something else, usually a string or a number.

The smallest script that triggers it

Triggers the errorline 5: error here
local TweenService = game:GetService("TweenService")
local part = workspace.Door
 
local info = TweenInfo.new(1)
local tween = TweenService:Create(part.Name, info, { Transparency = 1 })

The fix

Fixedline 5: the fix
local TweenService = game:GetService("TweenService")
local part = workspace.Door
 
local info = TweenInfo.new(1)
local tween = TweenService:Create(part, info, { Transparency = 1 })

TweenService:Create needs the object to animate. part.Name is only its name, which is a string.

Common causes

  1. A name (string) was passed where the object itself was needed.
  2. FireClient was called without the player as its first argument.
  3. Arguments are in the wrong order, so a number or table lands in the slot for an Instance.

Practice this until it sticks

A Deep Dive on Instances and function arguments: 5-minute lessons, each with a quiz. What you miss comes back in the next module. One Deep Dive a day is free. No card.