Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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
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. Evadable 65 — 9y

1 answer

Log in to vote
1
Answered by
Kyokamii 133
9 years ago

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

0
Because the rest seems useless. Kyokamii 133 — 9y
0
Yes, but I have the '' or '' there because I want to have multiple maps, not just one map. Evadable 65 — 9y
0
You would need to get a table then. Ill edit the inline code Kyokamii 133 — 9y
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. Kyokamii 133 — 9y
View all comments (4 more)
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. Evadable 65 — 9y
0
Hmm. Maybe check for table[math.random(#table)] once? Kyokamii 133 — 9y
0
It will check for one random map in the table. Kyokamii 133 — 9y
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. Evadable 65 — 9y
Ad

Answer this question