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

Can't change value of StringValue?

Asked by
Spoookd 32
6 years ago
Edited 6 years ago

I am trying to choose maps from the ReplicatedStorage and set the value of a StringValue to the name of the map:

01local players = game.Players:GetChildren()
02local maps = game.ReplicatedStorage.Maps:GetChildren()
03local currentmap = game.Workspace:WaitForChild("CurrentMap")
04local chosen = script.ChosenMap
05local spawner = game.Workspace.Spawn -- Change name
06local choices = {maps}
07 
08function choose()
09    for i = 1,#maps do
10        if maps[i]:IsA("Model") then
11            maps[i] = #choices + 1 -- I was told to use '#choices + 1 = maps[i]' but it can't go like that.
12        end
13    end
14    local picked = math.random(1, #choices)
15    print(choices[picked])
16    chosen.Value = choices[picked].Name
17    wait()
18end

Some of this code was changed a bit from someone in my last post.

But it just prints table: 33931ACC and an error pops up every time and I can't figure out why: Workspace.CurrentMap.Script:25: bad argument #3 to 'Value' (string expected, got nil)

0
How is the table maps created since you assign the value of choices there User#5423 17 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

This is because on line 6, you put the GetChildren() table inside of a table. You basically put a table inside of a table. Remove the {} around maps, and it should work.

Ad
Log in to vote
0
Answered by 6 years ago

Do picked = math.random(#maps) and remove the whole function since you don't even call it unless I'm looking at it wrong.

Also for future reference, you can call workspace by doing just workspace instead of game.Workspace

0
Remove choices while you're at it, unused variable after removing function masterblokz 58 — 6y
0
I call it in another function. Spoookd 32 — 6y
0
He should be using game.Workspace, not workspace. Global “workspace” just got deprecated recently User#19524 175 — 6y
0
He should be using game.Workspace, not workspace. Global “workspace” just got deprecated recently User#19524 175 — 6y
0
Pretty sure Workspace is deprecated, not workspace masterblokz 58 — 6y

Answer this question