Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can't change value of StringValue?

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)

1 comment

0

How is the table maps created since you assign the value of choices there

2 answers

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.

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

5 comments

0

Remove choices while you're at it, unused variable after removing function

0

I call it in another function.

0

He should be using game.Workspace, not workspace. Global “workspace” just got deprecated recently

0

He should be using game.Workspace, not workspace. Global “workspace” just got deprecated recently

0

Pretty sure Workspace is deprecated, not workspace

This discussion is preserved as it was. New answers, comments, and votes are closed.