Xeranus
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 1101 |
|
|
| 05 Dec 2014 10:25 PM |
Hello, I've been having trouble with a script that moves a Model in workspace called, "Sign" It's supposed to, move it right 10 studs smoothly, so like sliding not teleporting. Then move it back again 10 studs, then repeat. Sorry if its very bad, I haven't scripted in a while...
i = game.Workspace.Sign:GetChildren()
while true do
for i = 1,10 do wait(0.01) i.CFrame = CFrame.new(1, 1, 1) end
for i = 1,10 do wait(0.01) i.CFrame = CFrame.new(-1, -1, -1) end end
Output says: 23:20:52.936 - Workspace.Sign.Script:7: attempt to index local 'i' (a number value)
I'd gladly appreciate it if you could help! |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2014 10:29 PM |
You have i assigned to the counter value of for i=1,10 and also the children of sign.
parts = game.Workspace.Sign:GetChildren() for i=1,#parts do parts[i].CFrame = CFrame.new(parts[i].Position+Vector3.new(1,1,1)) end for i=1,#parts do parts[i].CFrame = CFrame.new(parts[i].Position-Vector3.new(1,1,1)) end
I dont know if this will work
♫♪ repeat wait() until 1+1 ~= 2 ♪♫ |
|
|
| Report Abuse |
|
|
cycoboy83
|
  |
| Joined: 31 May 2011 |
| Total Posts: 831 |
|
|
| 05 Dec 2014 10:34 PM |
Your first problem is that GetChildren() returns a table containing the parts, so attempting to CFrame that is just going to cause another error. Secondly, when you use for i = 1,10, you actually copy over that table with the integer value that that loop is at.
So essentially, change your variable names. Either the i in your for loop or the i for the GetChildren(). Secondly, I'm pretty sure rather than using GetChildren, you could just set a primarypart by using
game.Workspace.Sign.PrimaryPart = game.Workspace.Sign.PartName
then just CFraming the entire model via
game.Workspace.Sign:SetPrimaryPartCFrame(CFrame.new(x,y,z)) |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2014 10:35 PM |
:O That's so useful Is that new?
♫♪ repeat wait() until 1+1 ~= 2 ♪♫ |
|
|
| Report Abuse |
|
|
Xeranus
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 1101 |
|
|
| 05 Dec 2014 10:42 PM |
| Thanks, but may I ask, what does setting a primary part do? Please excuse my stupidness... |
|
|
| Report Abuse |
|
|
cycoboy83
|
  |
| Joined: 31 May 2011 |
| Total Posts: 831 |
|
|
| 06 Dec 2014 12:34 AM |
| I'm no expert on CFrame but from my experiences, rotating or moving that part around via SetPrimaryPartCFrame will move everything inside that model too. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Dec 2014 12:35 AM |
| It's the part that actually takes on the given CFrame and everything else moves/rotates relative to that |
|
|
| Report Abuse |
|
|
|
| 06 Dec 2014 01:15 AM |
CFrame is absolute position. Vector3 adds to the current position. Suppose you have a part on 1,2,2 You use Vector3.new(5,7,5) so 1+5=6,2+7=9,2+5=7 That means the part will move to 6,7,7. But CFrame, on the other hand, moves it to a absolute position. Take the part that is on 6,7,7. Use CFrame.new(0,0,0) on it. It goes back to 0,0,0 |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|