Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[SOLVED] Cannot set StringValue to a string chosen from an array?

Asked by 4 years ago
Edited 4 years ago

Hello!

So I'm making a game with a character I would like to have a random name. I created two arrays or lists (whatever you choose to call them), each of them filled with names for the chosen gender (a random number between 0 and 1). Then, I checked the gender, and set the StringValue, "Name"'s value to the chosen name. I got the error:

Workspace.TourGuideData:21: attempt to index field 'Name' (a string value)

It sounds complicated, but it really isn't.

So here's my script:

---------------------------------------
------ Written by ProqrammedGreen -----
---------------------------------------

print("TourGuideData - Initialized")

berryColor = script.BerryColor
name = script.Name
skinTone = script.SkinTone

--< Randomize >--

berryColor.Value = BrickColor.Random()
skinTones = {"Pine cone", "Dirt brown", "Fawn brown", "Cashmere", "Khaki", "Buttermilk", "Institutional white", "Burnt sienna", "Teal"}
skinTone.Value = BrickColor.new(skinTones[math.random(1, #skinTones)])
gender = math.random(0,1)
names = nil
if gender == 1 then
    names = {"Mary","Sarah","Emma","Jamie","Eva","Jen","Alexandra", "Patricia"}
    script.Name.Value = names[math.random(1,#names)]
else
    names = {"John", "Matthew", "Patrick", "James", "Max"}
    script.Name.Value = names[math.random(1,#names)]
end

Can someone help me figure out why I am getting this error and what I can do to fix it? Thanks!

-ProqrammedGreen

0
Fixed. I realized Name is also a property of a script, so I changed the name of the stringvalue to "namevalue proqrammed 285 — 4y
0
Fixed. I realized Name is also a property of a script, so I changed the name of the stringvalue to "namevalue" to not confuse the script proqrammed 285 — 4y
0
cheers royaltoe 5144 — 4y

Answer this question