fwep67
|
  |
| Joined: 21 Nov 2009 |
| Total Posts: 352 |
|
|
| 20 Jul 2015 01:18 PM |
So Im trying to make a script where it picks a random item to spawn, and it spawns that random item at each spawnpoint in a folder. (The spawns are parts) Here is the script:
local v1 = game.Lighting.Items.SmallHealthPack local v2 = game.Lighting.Items.MediumHealthPack local v3 = game.Lighting.Items.LargeHealthPack local v4 = game.Lighting.Items.Ammo local ids={v1,v2,v3,v4}; local Spawns = game.Workspace.ItemSpawns:GetChildren() for q = 1, #Spawns do local item = (ids[math.random(#ids)]):Clone() item.Parent = game.Workspace print(Spawns.CFrame) item.Main.CFrame = Spawns.CFrame --Error line
end The error message is CFrame expected, but got nil. How could I fix this? |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2015 01:22 PM |
ocal v1 = game.Lighting.Items.SmallHealthPack
local v2 = game.Lighting.Items.MediumHealthPack
local v3 = game.Lighting.Items.LargeHealthPack
local v4 = game.Lighting.Items.Ammo
local ids={v1,v2,v3,v4}; local Spawns = game.Workspace.ItemSpawns:GetChildren() for q = 1, #Spawns do
local item = (ids[math.random(#ids)]):Clone() item.Parent = game.Workspace print(Spawns.CFrame) item.Main.CFrame = CFrame.new(Spawns.Position)
end |
|
|
| Report Abuse |
|
|
fwep67
|
  |
| Joined: 21 Nov 2009 |
| Total Posts: 352 |
|
|
| 20 Jul 2015 01:27 PM |
| The error is still on the same line, it is (Workspace.SpawnItems:18: bad argument #1 to 'new' (Vector3 expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2015 01:28 PM |
local v1 = game.Lighting.Items.SmallHealthPack
local v2 = game.Lighting.Items.MediumHealthPack
local v3 = game.Lighting.Items.LargeHealthPack
local v4 = game.Lighting.Items.Ammo
local ids={v1,v2,v3,v4}; local Spawns = game.Workspace.ItemSpawns:GetChildren() for q = 1, #Spawns do
local item = (ids[math.random(#ids)]):Clone() item.Parent = game.Workspace print(Spawns.CFrame) item.Main.CFrame = CFrame.new(q.Position)
end |
|
|
| Report Abuse |
|
|
EvanHolt
|
  |
| Joined: 06 Sep 2008 |
| Total Posts: 1264 |
|
|
| 20 Jul 2015 01:34 PM |
You need a [q] after "Spawns" within the for loop. Spawns is defined as a ":GetChildren()," this means that it's a table of objects. You can't get the CFrame of a table. When you use Spawns[q] it returns the q-th item in the table Spawns. If you can't figure out where I got q from, it's the iterator of the for loop (q = 1), the number that tells you how many times the loop has been run.
Try this code:
local v1 = game.Lighting.Items.SmallHealthPack
local v2 = game.Lighting.Items.MediumHealthPack
local v3 = game.Lighting.Items.LargeHealthPack
local v4 = game.Lighting.Items.Ammo
local ids={v1,v2,v3,v4}; local Spawns = game.Workspace.ItemSpawns:GetChildren() for q = 1, #Spawns do local item = (ids[math.random(#ids)]):Clone() item.Parent = game.Workspace print(Spawns[q].CFrame) item.Main.CFrame = CFrame.new(Spawns[q].Position)
end
[ George Orwell taught me math! 2 + 2 = 5 ] |
|
|
| Report Abuse |
|
|
fwep67
|
  |
| Joined: 21 Nov 2009 |
| Total Posts: 352 |
|
|
| 20 Jul 2015 01:35 PM |
I got it. It was my mistake sorry :(
|
|
|
| Report Abuse |
|
|
EvanHolt
|
  |
| Joined: 06 Sep 2008 |
| Total Posts: 1264 |
|
|
| 20 Jul 2015 01:37 PM |
No problem.
[ George Orwell taught me math! 2 + 2 = 5 ] |
|
|
| Report Abuse |
|
|