|
| 11 Mar 2016 04:34 PM |
ay, been a while
Im making a script for fun, but it's being mean );
Output says: Workspace.lootSpawn.lootScript:18: bad argument #1 to 'new' (string expected, got nil)
Script says:
local possibleDrops = {} local itemCount = 1
local storage = game.ReplicatedStorage local dropPoint = script.Parent.Position
for i,v in pairs (storage:GetChildren()) do -- v will be the name of the item, and i will be the number of the item possibleDrops[i] = v print(possibleDrops[i]) end
function randomNumber () math.randomseed(tick()) local whichDrop = math.random(itemCount) drop = storage:FindFirstChild(possibleDrops[whichDrop]) placement = Instance.new(drop, workspace) placement.Position = dropPoint end
game.Players.PlayerAdded:connect(randomNumber)
What's wrong? Thanks! |
|
|
| Report Abuse |
|
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 11 Mar 2016 04:38 PM |
> placement = Instance.new(drop, workspace)
Instance.new expects the first argument to be a string corresponding to the type that you want the Instance to be, like "Part"
you probably want to use the Clone method on drop and then set its Parent value btw, there's no 'possiblDrops[whichDrop]' in storage, i'd check that logic again
next time look at the wiki
|
|
|
| Report Abuse |
|
|
|
| 11 Mar 2016 04:42 PM |
Doesn't: possibleDrops[i] = v
save the name of the object from storage (which would be a string) into possibleDrops?
#code --u guys r lame |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2016 04:54 PM |
New Script with new issue:
Output: #code Workspace.lootSpawn.lootScript:20: attempt to call method 'Clone' (a nil value)
Code: #code
local possibleDrops = {} local itemCount = 1
local storage = game.ReplicatedStorage local dropPoint = script.Parent.Position
for i,v in pairs (storage:GetChildren()) do -- v will be the name of the item, and i will be the number of the item possibleDrops[i] = v print(possibleDrops[i]) end
function randomNumber () math.randomseed(tick()) local whichDrop = math.floor(math.random(itemCount)) dropString = storage:FindFirstChild(possibleDrops[whichDrop]) drop = tostring(dropString) placement = drop:Clone() placement.Parent = workspace placement.Position = dropPoint end
game.Players.PlayerAdded:connect(randomNumber)
|
|
|
| Report Abuse |
|
|
|
| 11 Mar 2016 04:55 PM |
pardon the #codes, was testing R+ but im stupid
|
|
|
| Report Abuse |
|
|
os_time
|
  |
| Joined: 15 Feb 2014 |
| Total Posts: 2247 |
|
|
| 11 Mar 2016 04:59 PM |
Wait You are trying to clone a string?
http://lmgtfy.com/?q=Roblox+Wiki #code "Lua ~ PHP ~ CSS ~ HTML for me at least." |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2016 05:21 PM |
No, I'm cloning an object (tool)
|
|
|
| Report Abuse |
|
|
| |
|
| |
|