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.
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.
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))
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!