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
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)]