|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 26 Apr 2017 04:31 AM |
| I still get the same error. |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 26 Apr 2017 04:32 AM |
| i is not a valid member of Folder. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 26 Apr 2017 04:42 AM |
| game.ReplicatedStorage.Objects.Hairs[tostring(YOUR VALUE GOES HERE.)] |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 26 Apr 2017 04:57 AM |
| You aren't stupid you're learning. |
|
|
| Report Abuse |
|
|