generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: CFrame Troubleshooting

Previous Thread :: Next Thread 
fwep67 is not online. 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
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
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 is not online. 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
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image