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

How do I CFrame a model? As in move a whole model at the same time?

Asked by
mxpvjn 75
8 years ago
Edited 8 years ago

I'm trying to make a script where when the player pressed b they can spawn a certain model. And the model starts from the air and slowly comes down. But I don't know how to move the bricks at the same time.

My current script which I know wont work:

01player = game.Players.LocalPlayer
02mouse = player:GetMouse()
03CanUse = true
04mouse.KeyDown:connect(function(key)
05-- Detects if keydown is pressed
06    if key == "b" then
07        CanUse = false
08        print ("spawning model....")
09        BG = game.Lighting.BegginerBricks:clone("BG")
10        BG.Parent = game.Workspace
11        BG.CFrame = player.Character.Torso.CFrame * CFrame.new(0,100,0)
12        for i = 100, 0, -.5 do
13            BG.CFrame = player.Character.Torso.CFrame * CFrame.new(0,i,0)
14            wait()
15        end
16    end
17end)

Solved! to anybody who needs it here is my full working script.

01player = game.Players.LocalPlayer
02mouse = player:GetMouse()
03CanUse = true
04mouse.KeyDown:connect(function(key)
05-- Detects if keydown is pressed
06    if key == "b" then
07        CanUse = false
08        print ("spawning model....")
09        BG = game.Lighting.BegginerBricks:clone("BG")
10        BG.Parent = game.Workspace
11        BG:SetPrimaryPartCFrame(player.Character.Torso.CFrame * CFrame.new(0,100,0))
12        PositionWhenCalled = player.Character.Torso.CFrame
13        for i = 100, 0, -.5 do
14            BG:SetPrimaryPartCFrame(PositionWhenCalled*CFrame.new(0,i,0))
15            wait()
16        end
17    end
18end)

1 answer

Log in to vote
1
Answered by 8 years ago

To do this you will need to use SetPrimaryPartCFrame and PrimaryPart. Recently models have been added a SetPrimaryPartCFrame function. To explain this to you, I'll need to explain what a PrimaryPart is first.

Probably in maths sometime you have learned about rotation and centers. This is what happens in ROBLOX, the PrimaryPart is the center of the model, in wich the whole model will go around it.

If the PrimaryPart is in the middle, the whole model will go exactly where you want.

Then, we have SetPrimaryPartCFrame, who selects the PrimaryPart, CFrames it to where you want and everything around it goes in the same direction CFrame you use.

Let's say you have a boat, and a PrimaryPart on the middle. If you CFrame it an extra 5 Y, everything else would have an extra 5 Y. If you CFrame it an extra 3 Z and -5 X, everything else would have an extra 3 Z and -5 X.

Therefore, you only need to do :SetPrimaryPartCFrame() !

Hope this works it out for you! If it doesn't please comment how I could improve this answer. ;)

0
To set a PrimaryPart you have to go on properties of the model, and change it's PrimaryPart manually. Or, you could do model.PrimaryPart = model.Part! marcoantoniosantos3 200 — 8y
Ad

Answer this question