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

Having some troubles with "WaitFor and FindFirst"? in multiple inserted models from another script

So essentially, I have a script that clones maps from the Lighting (inefficient I know, should be in ReplicatedStorage), but it inserts them fine however I keep running into trouble is when I click on this script which is in a textbutton, it always searches for the first model but never the second or etc however many maps I include. Could anyone shed some light onto how I might be able to fix this?

local SpawnPos = game.Workspace:WaitForChild(('MapNameSpawns' or '' or '')):GetChildren()
local plr = game.Players.LocalPlayer
local char = plr.Character
if not char or not char.Parent then
char = plr.CharacterAdded:wait()
end

--filter function

function onClick() 
	Filter() 
	if #SpawnPos > 0 then
		local CSpawn = SpawnPos[math.random(1, #SpawnPos)]
		local FindValue = game.Players.LocalPlayer.CharStorage:WaitForChild("NameValue")
		if FindValue.Value == true then
		char:MoveTo(CSpawn.Position)		
		script.Parent.Parent.Visible = false
		script.Parent.Parent.Parent.TextButton.Visible = false
		else
		if FindValue == false then
			print("whoops")
				end
			end
		end
	end

1 comment

0

Also, note that this script is searching for a model that is inserted and has several "spawns", and it chooses a random one, it isn't looking for a random map, it's looking for choose a random brick to move the player out of many, and these bricks are cloned into the workspace along with the map.

1 answer

You should get a table to the first line. Here's an example: maps = {workspace.Map1, workspace.Map2, workspace.Map3} To access a table, you must do maps[1] or maps[2] or maps[3] to access each variable in the table chosenMap = maps[math.random(#table)]

8 comments

0

Because the rest seems useless.

0

Yes, but I have the '' or '' there because I want to have multiple maps, not just one map.

0

You would need to get a table then. Ill edit the inline code

0

The rest of your script is made for a table not for a basic variable lmao. Change the first line to a table and it should work.

0

Very true, but the script won't know which map to choose also, it creates an error because it searches for the entire table when creating the table.

0

Hmm. Maybe check for table[math.random(#table)] once?

0

It will check for one random map in the table.

0

Sorry if I wasn't clear on the description but what I wanted was to find a model in the workspace, and it will switch after X amount of time and load a new map but, the model I want to find only contains the spawns which is why want them to move to a random brick in the spawn model.

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