Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Unable to cast Vector3 to CoordinateFrame?

Asked by 4 years ago

Hello, how do I fix this error Unable to cat Vector3 to CoordinateFrame? It's on line 29.

local Players = game:GetService("Players");
local InsertService = game:GetService("InsertService");

local Cars = {5083437873, 5083676767}

Players.PlayerAdded:Connect(function(player)
    while true do
            local character  = player.Character or player.CharacterAdded:Wait()--waits for the character if not already loaded

    local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")

    local carId = Cars[math.random(1, #Cars)];
    local root = InsertService:LoadAsset(carId);

      local instances = root:GetChildren()
      if #instances == 0 then
          root:Destroy()
          return
      end

      root = root:GetChildren()
      if #root == 1 then
          root = root[1]
      else return end
      print(root)
      root.Body.Drive.Disabled = false
      root.Parent = workspace

    root:SetPrimaryPartCFrame(HumanoidRootPart.Position)
    end
end)
0
Vector3 ~= CFrame. Cast a CFrame. Ziffixture 6913 — 4y

1 answer

Log in to vote
1
Answered by
blazar04 281 Moderation Voter
4 years ago

You are getting this error because you are trying to set root's primary part CFrame and HumanoidRootPart.Position is not a CFrame–it is a Vector3 coordinate. Instead use HumanoidRootPart.CFrame

Ad

Answer this question