|
| 10 Mar 2015 04:48 PM |
I need a for loop that chooses a random one from a table, but still be able to mess with that one I chose...
like a mixture of...
for _,car in pairs(Cars)do -- I need the 'car' variable
and
for x = (math.random(#Cars)),#Cars do -- I need the random choice from table
Unless of course I can move a model without the joints breaking...
Can you merge the 2 for loops? or is it easier just to move a model as a Whole?
you have 10 minutes. GO. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 10 Mar 2015 04:51 PM |
| Explain yourself. The fact you have no idea what you're saying shows you cannot complete this, and is probably not worth our time for free scripting and leeching. |
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 10 Mar 2015 04:51 PM |
"Unless of course I can move a model without the joints breaking..."
model:MakeJoints() ?
And I'm not sure what you want.. Do you want something that pulls a random element out of a table, and removes it from the table?
If that's the case then you can make a shallow copy of the table and then use table.remove to remove elements from the copied table. |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 10 Mar 2015 04:53 PM |
| Pretty sure the :MoveTo() method of Models (not Humanoid) will move it while keeping joints |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 04:55 PM |
"don't know what you're talking about"
Exactly. That is exactly how I felt. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 04:56 PM |
I need it to teleport, no :MoveTo()
basically,
for _,car in pairs(My table) do
always goes in the same order. I cant have this. I need it to be random... wait...
local num = math.random(7) if num == 3 then --blah blah blah end
would that work to randomize it? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 04:58 PM |
| He wants to shuffle a table |
|
|
| Report Abuse |
|
|
| |
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 10 Mar 2015 05:00 PM |
local newTable = { };
for i =1, #myTable do local index = math.random(#myTable); local element = myTable[index]; table.insert(newTable, element); table.remove(myTable, index); end
for i, v in pairs(newTable) do --stuff end |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 10 Mar 2015 05:00 PM |
... Why don't you look into the MoveTo() function of models? It does 'teleport' the model. If you want to 'teleport' a model from one location to another, this is the easiest way to do so.
Description: Moves the center of the PrimaryPart to the given position. If a PrimaryPart has not been specified then the root part of the model will be used. Because the root part is not deterministic, it is recommended to always set a PrimaryPart when using MoveTo. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 05:03 PM |
| I have tried :MoveTo() and nothing happened. and I do NOT just want to shuffle a table... I still want the 'car' variable. |
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 10 Mar 2015 05:05 PM |
| .___________________________. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 05:06 PM |
| I need the random choice from the table, and the car variable. |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 10 Mar 2015 05:07 PM |
I just tried using MoveTo() with an unanchored, welded model. It worked exactly as intended.
Despite that, why don't you tell us what exactly you are trying to accomplish? You have not explained the problem well enough for anyone to assist you, and from what you've posted so far, your current method may be flawed or inefficient. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 05:10 PM |
ok, ok, ok
I have a car in ServerStorage, I need it to choose a random spawn... |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 10 Mar 2015 05:12 PM |
say 'Spawns' is an array of all your spawn positions and 'car' is the model
car:MoveTo(Spawns[math.random(#Spawns)])
? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 05:14 PM |
Do I have to use MoveTo...
I'd rather not... |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 10 Mar 2015 05:18 PM |
It makes the most sense, given the model is unanchored and welded...
There are other options, but I'm not really sure what you don't like about MoveTo()?
Anchoring the whole model, teleporting each part individually, welding with :MakeJoints(), and un-anchoring would be less efficient and accomplish nothing more if that's what you want. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 05:21 PM |
| I dislike MoveTo. I prefer SetPrimaryPartCFrame, and I will never use MoveTo EVER again. |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 10 Mar 2015 05:25 PM |
| ^ Will accomplish the same thing, just don't forget to set a PrimaryPart |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 05:29 PM |
| uhhh how do I set the PrimaryPart... |
|
|
| Report Abuse |
|
|
| |
|
|
| 10 Mar 2015 05:33 PM |
wait, my table has problems...
local Spawns = { [1] = Vector3.new(121,3,54); [2] = Vector3.new(100,3,200); [3] = Vector3.new(200,3,100)}
local car = game.ServerStorage.Car:Clone() car:SetPrimaryPartCFrame(Spawns[math.random(#Spawns)])
Unable to cast Vector3 to CoordinateFrame |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 10 Mar 2015 05:35 PM |
CFrame != Vector3
You can change the table to CFrames, or simple convert a Vector3 to a default-orientation CFrame with the following:
CFrame.new(Vector3)
car:SetPrimaryPartCFrame(CFrame.new(Spawns[math.random(#Spawns)]))
|
|
|
| Report Abuse |
|
|
|
| 10 Mar 2015 05:44 PM |
| yeah, I figured that out, Thanks to Jared for SetPrimaryPartCFrame |
|
|
| Report Abuse |
|
|