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