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
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.