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

I'm trying to make multiple children slide at once - what am I doing wrong?

Asked by
Narroby 10
9 years ago
 button = script.Parent
 doors = script.Parent.Parent.CellDoors:GetChildren()

 function onClicked()

     for i,v in pairs(doors) do
       for c = 1, 7, .1 do
    v.CFrame = v.CFrame * CFrame.new(c, 0, 0)
    wait(0.1)

    end

    end

 end

 button.ClickDetector.MouseClick:connect(onClicked)

First, please keep in mind that i'm have very basic scripting knowledge.

With my very limited experience on ROBLOX Lua, after reading this, I'd imagine that once the button is pressed, every children in the model "CellDoors" would slowly slide in a direction, until it had traveled 7 studs.

That's, of course, not what's happening.

When I click the button, the doors, one by one, slide 244 STUDS in one direction - and I am completely baffled as to why this is happening. I must be committing a pretty big mistake, because i don't understand how the number 244 would come into a play, and I don't understand why the doors are sliding one by one instead of all at the same time.

Could anyone shed some light on what it is that I'm failing horribly at doing?

0
You forgot to change one of the CFrame axis's "c". EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Instead of moving all of celldoors children, you can just change the CFrame of a model.


You can do this using :SetPrimaryPartCFrame().

workspace.Player1:SetPrimaryPartCFrame(0,0,0) --Sends the player to 0,0,0.

To do this we need a primary part. In the command bar, you can use this code: workspace:FindFirstChild("CellDoors", true).PrimaryPart = workspace:FindFirstChild("CellDoors", true).Part--Or something.

--Now that your model has a PrimaryPart... Finished script:
button = script.Parent
doors = script.Parent.Parent.CellDoors

function onClicked()

      for c = 1, 7, .1 do
   CellDoors:SetPrimaryPartCFrame(c, 0, 0)
   wait(0.1)

   end

end

button.ClickDetector.MouseClick:connect(onClicked)


Hope it helps!

Ad

Answer this question