Stellar AI

Errors

Roblox 'Unable to cast value to Object' – Fix

The error

ServerScriptService.Teleporter:9: Unable to cast value to Object

What it means

A Roblox engine function needed an Instance (a Player, Part, Model or similar) and you passed a different type: a UserId instead of a Player, a CFrame or Position instead of the part, or a table where one object was required. The message does not name the argument, so check each value on the line against the function's parameter list in the Creator docs.

The fix

-- TweenService:Create needs the Instance, not its CFrame
local TweenService = game:GetService("TweenService")
local door = workspace:WaitForChild("Door")
local info = TweenInfo.new(1)
local tween = TweenService:Create(door, info, {
  CFrame = door.CFrame + Vector3.new(0, 8, 0)
})
tween:Play()

-- PromptGamePassPurchase needs the Player, not player.UserId
local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService:PromptGamePassPurchase(player, gamePassId)

-- FireClient needs one Player, not Players:GetPlayers()
remote:FireClient(player, payload)

If you only have a UserId, look the player up with Players:GetPlayerByUserId and check they are still in the server before calling the function. For older raycast helpers, FindPartOnRay accepts one ignore Instance; a list needs FindPartOnRayWithIgnoreList, or better workspace:Raycast with RaycastParams.FilterDescendantsInstances.

These steps are for creators and server owners working on their own scripts. Test the change on a development server or in Studio before you put it live.

Related tools: Roblox script generator · Roblox Lua error fixer · all script generators