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

bad argument #1 to '?' (Vector3 expected, got nil)

local spawnlocation = {"SpawnLocation1","SpawnLocation2","SpawnLocation3","SpawnLocation4","SpawnLocation5","SpawnLocation6"}
spawnlocation.Parent = game.Workspace
script.Parent.MouseButton1Click:connect(function()
	for i= 1,#spawnlocation do
	game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(spawnlocation[math.random(1,#spawnlocation)].Position + Vector3.new(0, 3, 0))
	wait(1)
	script.Parent.Parent:remove()
	end
end)

Not sure why I get this error. What this script is supposed to do is move the character to a random spawn. Any ideas? :/

1 comment

1

The SpawnLocations are strings, you need to have actual objects to get the Position.

2 answers

✓ Accepted answer

The strings are not the problem it is just you need to reference a part for getting the position of the spawnpoint. You can use something like this:

local spawnlocation = {"SpawnLocation1","SpawnLocation2","SpawnLocation3","SpawnLocation4","SpawnLocation5","SpawnLocation6"}
spawnlocation.Parent = game.Workspace
script.Parent.MouseButton1Click:connect(function()
    for i= 1,#spawnlocation do
    game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(workspace[spawnlocation[math.random(1,#spawnlocation)]].Position + Vector3.new(0, 3, 0))
    wait(1)
    script.Parent.Parent:remove()
    end
end)

1 comment

0

Thank you! It worked!

You are creating strings in the spawnlocation table, instead of referencing the parts.

On line 1, instead of

local spawnlocation = {"SpawnLocation1","SpawnLocation2","SpawnLocation3","SpawnLocation4","SpawnLocation5","SpawnLocation6"}

it should be

local spawnlocation = {game.Workspace.SpawnLocation1,game.Workspace.SpawnLocation2,game.Workspace.SpawnLocation3,game.Workspace.SpawnLocation4,game.Workspace.SpawnLocation5,game.Workspace.SpawnLocation6}

assuming your SpawnLocation parts are children of Workspace.

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