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

What does this error mean?

Asked by
JJ_B 250 Moderation Voter
9 years ago

When I run one of my scripts, I get this error in the output: "Workspace.BridgeDeck.Bridge.Science/Engineering.Part.Script:13: bad argument #1 to '?' (Vector3 expected, got nil)"

Line 13 of said script is as follows: p.CFrame = p.CFrame + Vector3.new(0,0,10)

Does anyone know why this won't work?

[EDIT] The whole script:

01function separate()
02if game.Workspace:FindFirstChild("Stardrive")== nil then
03    script.Parent.Sound.Pitch = 1
04    script.Parent.Sound:play()
05    wait(3)
06    local s = game.ServerStorage.Stardrive:clone()
07    s.Parent = game.Workspace
08    game.Workspace.Separated.Value = true
09    wait(0.5)
10    local p = game.Workspace.Stardrive:GetChildren()
11        for i = 1,#p do
12        repeat
13            p.CFrame = p.CFrame + Vector3.new(0, 0, 10)
14            wait(0.5)
15        until
View all 28 lines...
0
http://wiki.roblox.com/index.php/Lua_errors -- check here for lua errors. HungryJaffer 1246 — 9y
0
Where is the script located, and what is 'p'? dyler3 1510 — 9y
0
I tested this to make sure, and it works fine. You sure this is the right line? Perci1 4988 — 9y
1
I'll give the whole script if you want. JJ_B 250 — 9y
View all comments (3 more)
0
Yea, that'd help. I tested also, and it worked perfectly. dyler3 1510 — 9y
1
Edited accordingly. JJ_B 250 — 9y
1
Thanks so much dude, you hit me up to 200 rep :D dyler3 1510 — 9y

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

Oh, you're problem is that you're trying to index a table. You can't do that, you need to iterate through each object in the table instead. An example is here:

1p=game.Workspace:GetChildren()
2for i,v in pairs(p) do --Creates a loop that iterates through each value in the table.
3    if v:IsA("BasePart") then
4        v.CFrame = v.CFrame + Vector3.new(0, 0, 10)
5    end
6end

So there's an example. To apply this to your script, we will keep everything else the same, and fix up your loop:

01function separate()
02if game.Workspace:FindFirstChild("Stardrive")== nil then
03    script.Parent.Sound.Pitch = 1
04    script.Parent.Sound:play()
05    wait(3)
06    local s = game.ServerStorage.Stardrive:clone()
07    s.Parent = game.Workspace
08    game.Workspace.Separated.Value = true
09    wait(0.5)
10    local p = game.Workspace.Stardrive:GetChildren()
11    repeat --Moved this outside of the 'for' loop. It would make each part move one at a time if not.
12        wait(0.5)
13        for i,v in pairs(p) do
14            v.CFrame = v.CFrame + Vector3.new(0, 0, 10) --Index's the value in the table
15        end
View all 27 lines...

Ok, so now your code should work correctly. If you have any further problems/questions, please leave a comment below. Hope I helped :P

-Dyler3

0
Sorry, I made a mistake. Give me a minute to update this. dyler3 1510 — 9y
0
Assuming that he wants all the parts to be moved at once, you have to switch the for and repeat. 'repeat for (stuff) end until condition' Perci1 4988 — 9y
0
Yup, I caught that, Already was fixing it :P Thanks tho dyler3 1510 — 9y
0
No errors as such, but the actual model doesn't move :-/ JJ_B 250 — 9y
Ad

Answer this question