generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Scripters, I may have a challenge.

Previous Thread :: Next Thread 
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
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 is not online. 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 is not online. 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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
10 Mar 2015 04:55 PM
"don't know what you're talking about"

Exactly. That is exactly how I felt.
Report Abuse
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
10 Mar 2015 04:58 PM
He wants to shuffle a table
Report Abuse
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
10 Mar 2015 05:00 PM
YEP!
Report Abuse
LucasLua is not online. 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 is not online. 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
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
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 is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
10 Mar 2015 05:05 PM
.___________________________.
Report Abuse
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
10 Mar 2015 05:06 PM
I need the random choice from the table, and the car variable.
Report Abuse
jewelycat is not online. 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
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
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 is not online. 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
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
10 Mar 2015 05:14 PM
Do I have to use MoveTo...

I'd rather not...
Report Abuse
jewelycat is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
10 Mar 2015 05:21 PM
I dislike MoveTo. I prefer SetPrimaryPartCFrame, and I will never use MoveTo EVER again.
Report Abuse
jewelycat is not online. 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
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
10 Mar 2015 05:29 PM
uhhh how do I set the PrimaryPart...
Report Abuse
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
10 Mar 2015 05:31 PM
nvm
Report Abuse
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
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 is not online. 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
FunkiAndrew is not online. FunkiAndrew
Joined: 01 Dec 2013
Total Posts: 2318
10 Mar 2015 05:44 PM
yeah, I figured that out, Thanks to Jared for SetPrimaryPartCFrame
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image