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
5 years ago
Edited 5 years ago

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

local players = game.Players:GetChildren()
local maps = game.ReplicatedStorage.Maps:GetChildren()
local currentmap = game.Workspace:WaitForChild("CurrentMap")
local chosen = script.ChosenMap
local spawner = game.Workspace.Spawn -- Change name
local choices = {maps}

function choose()
    for i = 1,#maps do
        if maps[i]:IsA("Model") then
            maps[i] = #choices + 1 -- I was told to use '#choices + 1 = maps[i]' but it can't go like that.
        end
    end
    local picked = math.random(1, #choices)
    print(choices[picked])
    chosen.Value = choices[picked].Name
    wait()
end

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 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 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 5 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 — 5y
0
I call it in another function. Spoookd 32 — 5y
0
He should be using game.Workspace, not workspace. Global “workspace” just got deprecated recently User#19524 175 — 5y
0
He should be using game.Workspace, not workspace. Global “workspace” just got deprecated recently User#19524 175 — 5y
0
Pretty sure Workspace is deprecated, not workspace masterblokz 58 — 5y

Answer this question