I got an unable to cast value to object error in my code and I cannot seem to figure out what the issue is.
The error pointed to line 23 which is if Target:IsDescendantOf(Vehicle) then
Target is of course the PlayerMouse’s Target
function GetModel(Target)
local Model
for _, Vehicle in pairs, workspace.Vehicles:GetChildren() do
if Target:IsDescendantOf(Vehicle) then
Model = Vehicle
end
end
if not Model then
Model = Target.Parent
end
return Model
end
and the line where this function fired was local Debris = GetModel(Target) or Target
function MouseMove(Mouse)
if IsAdministrator() and Enabled then
local Target = Mouse.Target
if Target then
if IsDebris(Target) then
local Debris = GetModel(Target) or Target
Selection.Parent = workspace.Terrain
Selection.Adornee = Debris
else
Selection.Adornee = nil
end
else
Selection.Adornee = nil
end
end
end
This is your problem. Vehicle is the same as workspace.Vehicles:GetChildren(), and that’s a table, not an Instance. You need to call pairs as a function rather than just pass it as an argument.