Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What does this error mean?

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:

function separate()
if game.Workspace:FindFirstChild("Stardrive")== nil then
	script.Parent.Sound.Pitch = 1
	script.Parent.Sound:play()
	wait(3)
	local s = game.ServerStorage.Stardrive:clone()
	s.Parent = game.Workspace
	game.Workspace.Separated.Value = true
	wait(0.5)
	local p = game.Workspace.Stardrive:GetChildren()
		for i = 1,#p do
		repeat
			p.CFrame = p.CFrame + Vector3.new(0, 0, 10)
			wait(0.5) 
		until
			game.Workspace.Stardrive.Shape.Positon.Z <= 868.946
		end
else
	if game.Workspace:FindFirstChild("Stardrive")~= nil then
		script.Parent.Sound.Pitch = -1
		script.Parent.Sound:Play()
		game.Workspace.Separated.Value = false
		game.Workspace.Stardrive:destroy()
	end
end
end

script.Parent.ClickDetector.MouseClick:connect(separate)

7 comments

0

http://wiki.roblox.com/index.php/Lua_errors -- check here for lua errors.

0

Where is the script located, and what is 'p'?

0

I tested this to make sure, and it works fine. You sure this is the right line?

1

I'll give the whole script if you want.

0

Yea, that'd help. I tested also, and it worked perfectly.

1

Edited accordingly.

1

Thanks so much dude, you hit me up to 200 rep :D

1 answer

✓ Accepted answer

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:

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

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

function separate()
if game.Workspace:FindFirstChild("Stardrive")== nil then
    script.Parent.Sound.Pitch = 1
    script.Parent.Sound:play()
    wait(3)
    local s = game.ServerStorage.Stardrive:clone()
    s.Parent = game.Workspace
    game.Workspace.Separated.Value = true
    wait(0.5)
    local p = game.Workspace.Stardrive:GetChildren()
	repeat --Moved this outside of the 'for' loop. It would make each part move one at a time if not.
		wait(0.5) 
		for i,v in pairs(p) do
			v.CFrame = v.CFrame + Vector3.new(0, 0, 10) --Index's the value in the table
		end
	until  game.Workspace.Stardrive.Shape.Positon.Z <= 868.946
else
    if game.Workspace:FindFirstChild("Stardrive")~= nil then
        script.Parent.Sound.Pitch = -1
        script.Parent.Sound:Play()
        game.Workspace.Separated.Value = false
        game.Workspace.Stardrive:destroy()
    end
end
end

script.Parent.ClickDetector.MouseClick:connect(separate)

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

4 comments

0

Sorry, I made a mistake. Give me a minute to update this.

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'

0

Yup, I caught that, Already was fixing it :P Thanks tho

0

No errors as such, but the actual model doesn't move :-/

This discussion is preserved as it was. New answers, comments, and votes are closed.