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: Loop variable

Previous Thread :: Next Thread 
Valyrian_Advisor is not online. Valyrian_Advisor
Joined: 13 Apr 2013
Total Posts: 1703
26 Apr 2017 04:12 AM


local i = 0
local found = false
while i<10 and found == false do
if hairs.i.Name == hairstyle.Value then
hair.Mesh.MeshId = hairs.i.Mesh.MeshId
found = true
end
end

Hi, I tried using the variable of the loop "i" this way.
I have a folder in replicated storage with all the hair types and the name of the hair parts are numbers, from 1 to 10.
The player selects the hair he wants from a gui, and a Value gets the number of the hair.(this part is not included here).

I get this in the output: i is not a valid member of Folder
So I guess I made it wrong, how can I fix this issue with the "i" variable?
Report Abuse
Valyrian_Advisor is not online. Valyrian_Advisor
Joined: 13 Apr 2013
Total Posts: 1703
26 Apr 2017 04:13 AM
I forgot to include the i = i+1 in the post but it's present in the script.
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
26 Apr 2017 04:21 AM
hairs[tostring(i)].Name


But also I would suggest learning what a for loop is
http://wiki.roblox.com/?title=Loops#For
Report Abuse
ur_famous is not online. ur_famous
Joined: 27 Mar 2013
Total Posts: 246
26 Apr 2017 04:29 AM
local i = 0
local found = false
while i<10 and found == false do
i = i + 1
if hairs:GetChildren()[i].Name == hairstyle.Value then
hair.Mesh.MeshId = hairs:GetChildren()[i].Mesh.MeshId
found = true
end
end

That should do it ^


Signed, eiad999 - ur_famous ~ Holder of India ~ Holder of India of development ~ Founder of Legends Studios ~ Developer of Stormcage Containment Facility...
Report Abuse
Valyrian_Advisor is not online. Valyrian_Advisor
Joined: 13 Apr 2013
Total Posts: 1703
26 Apr 2017 04:31 AM
I still get the same error.
Report Abuse
ur_famous is not online. ur_famous
Joined: 27 Mar 2013
Total Posts: 246
26 Apr 2017 04:32 AM
Or you can do this:

local i = 0
local found = false
for i,v in pairs(hairs:GetChildren()) do
if found == true and v.Name == hairstyle.Value then
hair.Mesh.MeshId = v.Mesh.MeshId
end
end


Signed, eiad999 - ur_famous ~ Holder of India ~ Holder of India of development ~ Founder of Legends Studios ~ Developer of Stormcage Containment Facility...
Report Abuse
ur_famous is not online. ur_famous
Joined: 27 Mar 2013
Total Posts: 246
26 Apr 2017 04:32 AM
found = false*


Signed, eiad999 - ur_famous ~ Holder of India ~ Holder of India of development ~ Founder of Legends Studios ~ Developer of Stormcage Containment Facility...
Report Abuse
Valyrian_Advisor is not online. Valyrian_Advisor
Joined: 13 Apr 2013
Total Posts: 1703
26 Apr 2017 04:32 AM
i is not a valid member of Folder.
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
26 Apr 2017 04:33 AM
You have to change it in both places, I didn't see the other place sorry.

if hairs[tostring(i)].Name == hairstyle.Value then
hair.Mesh.MeshId = hairs[tostring(i)].Mesh.MeshId
Report Abuse
Valyrian_Advisor is not online. Valyrian_Advisor
Joined: 13 Apr 2013
Total Posts: 1703
26 Apr 2017 04:37 AM
I alredy changed it myself, but it's still not working.
Let's think it like this: I select the hair type, so the value becomes |Value = number|
Now I want to get the hair model which is inside here:

game.ReplicatedStorage.Objects.Hairs

I want to select the Hair whose name is = to the Value I found before.
How so?
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
26 Apr 2017 04:42 AM
game.ReplicatedStorage.Objects.Hairs[tostring(YOUR VALUE GOES HERE.)]
Report Abuse
Valyrian_Advisor is not online. Valyrian_Advisor
Joined: 13 Apr 2013
Total Posts: 1703
26 Apr 2017 04:55 AM
I'm so stupid, the loop was useless in this.
Thanks to everyone who tried to help!
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
26 Apr 2017 04:57 AM
You aren't stupid you're learning.
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