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
7 years ago
Edited 7 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:

player = game.Players.LocalPlayer
mouse = player:GetMouse()
CanUse = true
mouse.KeyDown:connect(function(key)
-- Detects if keydown is pressed
    if key == "b" then
        CanUse = false
        print ("spawning model....")
        BG = game.Lighting.BegginerBricks:clone("BG")
        BG.Parent = game.Workspace
        BG.CFrame = player.Character.Torso.CFrame * CFrame.new(0,100,0)
        for i = 100, 0, -.5 do
            BG.CFrame = player.Character.Torso.CFrame * CFrame.new(0,i,0)
            wait()
        end
    end
end)

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

player = game.Players.LocalPlayer
mouse = player:GetMouse()
CanUse = true
mouse.KeyDown:connect(function(key)
-- Detects if keydown is pressed
    if key == "b" then
        CanUse = false
        print ("spawning model....")
        BG = game.Lighting.BegginerBricks:clone("BG")
        BG.Parent = game.Workspace
        BG:SetPrimaryPartCFrame(player.Character.Torso.CFrame * CFrame.new(0,100,0))
        PositionWhenCalled = player.Character.Torso.CFrame
        for i = 100, 0, -.5 do
            BG:SetPrimaryPartCFrame(PositionWhenCalled*CFrame.new(0,i,0))
            wait()
        end
    end
end)

1 answer

Log in to vote
1
Answered by 7 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 — 7y
Ad

Answer this question