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

Help with Vector3 and CFrame? (attempt to multiply a Vector3 with an incompatible value type or nil)

Asked by 6 years ago

I have a part called base and a model with a map inside it and I am trying to make the model spawn 100 studs above the base so then I will be able to later add an effect where the bricks fall into place. This is currently what I have so far:

print("Load Test Map1...")
wait(2)
local base = game.Workspace.Base
local lighting = game:GetService("Lighting")
local maps = lighting:WaitForChild("Maps")
local mapList = maps:GetChildren()

function loadMap(map)
    map.Parent = workspace
    map:SetPrimaryPartCFrame(base.Position * CFrame.new(0,100,0))
end

loadMap(mapList[1])

I was just wondering how I would be able to get this to work because on the line where I SetPrimaryPartCFrame it says: "attempt to multiply a Vector3 with an incompatible value type or nil."

Thanks for any help/suggestions.

3 answers

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago
function loadMap (map)
    map.Parent = workspace
    local cf = CFrame.new(base.Position + Vector3.new(0 , 100 , 0))
    map:SetPrimaryPartCFrame(cf)
end

The + and * operator take on different meanings when used with different values. When the + operator is used with two Vector3 values, it returns a new Vector3 value that is translated by the other Vector3 For example, Vector3.new(4 , 5 , 6) + Vector3.new(0 , 1 , 0) would return a new Vector3 translated one stud up.

There is no + operator for two CFrames but there is the * operator which basically does the same thing. The * operator takes two CFrames and returns a new combined CFrame. For example, CFrame.new(2 , 1 , 3) * CFrame.new(0 , 1 , 0) would return a new CFrame translated up by one stud.

In your case, there is no operator + that accepts a Vector3 and CFrame. This is why the script is throwing an error.

0
I agree with this but I think the problem is that base.Position is a Vector3 so I am trying to do operations with a CFrame and a Vector3. I'm just unsure how I would handle this to make a grouped model's CFrame orient above a part. Boogieboon 30 — 6y
0
I just tested something around these lines and it worked! I was just wondering why it worked when you made it into a variable because when It was not a variable and I tried typing it inside it would give me an error. Thanks. Boogieboon 30 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You can't multiply a Vector3 and a CFrame in that order. You can, however, multiply a CFrame and a Vector3.

print("Load Test Map1...")
wait(2)
local base = game.Workspace.Base
local lighting = game:GetService("Lighting")
local maps = lighting:WaitForChild("Maps")
local mapList = maps:GetChildren()

function loadMap(map)
    map.Parent = workspace
    map:SetPrimaryPartCFrame(CFrame.new(0,100,0) * base.Position)
end

loadMap(mapList[1])

If that doesn't work, you could also try CFrame.new(base.Position + Vector3.new(0, 100, 0))

0
The multiplication operator returns a new Vector3 transformed from object space to world space.  I think you mean to use the add operator here. Even then, you are adding the wrong value. RayCurse 1518 — 6y
Log in to vote
-1
Answered by 6 years ago

I think the reason is that you cannot multiply a Vector3 by a CFrame, but you can multiply a CFrame by a Vector3 according to the wiki. So, just switch the factors around.

Hope this helps!

0
didnt help creeperhunter76 554 — 6y

Answer this question