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

Why isn't Roblox able to find my brick in a model?

Asked by
Seyfert 90
8 years ago

New here, hoping you get help me out. Before I paste the code I would like to give you a run down of what I am trying to do.

I have a Model in ServerStorage that is to get copied and placed into Workspace, after it is moved to Workspace, the code will check for certain conditions and then move the player(s) to a certain brick named "SpawnPoint" that is inside that newly moved Model. However, I keep getting the error attempt to index a nil value

models = game.ServerStorage.blah:GetChildren()
function movemodel() 
    t = models[math.random(1, #models)]:clone() 
    t.Parent = game.Workspace

end

while true do wait()
    wait()
    movemodel()
    wait(5)
    for i, v in pairs(game.Players:GetPlayers()) do
    if v.TeamColor == BrickColor.new("Bright yellow") then
    v.Character.Torso.CFrame = game.Workspace:FindFirstChild("SpawnPoint").CFrame + Vector3.new(0,3,0)

        end
    end

2 answers

Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago

I don't know exactly how your Objects are arranged in your Explorer, but shouldn't "SpawnPoint" be in a model located in game.Workspace instead of being directly in game.Workspace?

0
To demonstrate how I have it organized its Workspace > MODEL > SpawnPoint the main issue is that the MODEL is chosen with several other MODELS at random and each MODEL has a different name. So I can't simply put game.Workspace.MODELNAMEHERE.SpawnPoint as I won't know the MODEl name. I thought FindFirstChild would look everywhere in Workspace for the first child/brick named SpawnPoint? Seyfert 90 — 8y
1
Actually, yes, it can. If you pass 'true' to FindFirstChild as second argument, it will look recursively through the all the children and grand-children of the container you specified. Link150 1355 — 8y
Ad
Log in to vote
-2
Answered by
Seyfert 90
8 years ago

Not sure whats with the downvotes, I am asking a genuine question, if you paste in that code and put a Model in a model in ServerStorage it will not work for some strange reason.

0
Don't put an answer. Edit your question. DrCylonide 158 — 8y

Answer this question