Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does it say attempt to index nil value?

Asked by 5 years ago
Edited 5 years ago

local parent = script.Parent.Parent.Name

local item_settings = require(game.workspace.Item_Settings)

local values = item_settings[parent]

while wait(values[2]) do

if script.Parent.Parent.Parent.Name == "Purchased" then

local tycoon = script.Parent.Parent.Parent.Parent

local ore_storage = tycoon.Ore_Storage

local ore = script.Parent:Clone()

local cash = Instance.new("IntValue", ore)

ore.Name = "Ore"

ore.CanCollide = true

ore.Anchored = false

ore.Parent = ore_storage

cash.Name = "Cash"

cash.Value = values[1]

game.Debris:AddItem(ore, 20)

end

end

so basicaly the module is in workspace and im trying to make it where i can put the script in any dropper and not have to do anything to it

the error is in line 4 and values is the nil value parent is useing the name of the model and finds that same name in the module script and its a table with settings for the dropper like drop speed and ore value

0
Yo, please use the Code format. Just type "```lua" and end the block of code with "```". This is hard to read aha. Also please provide the line in which the error is printed on. Psudar 882 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Why does it say attempt to index nil value?

Whats wrong?

Well if we look at line 4 (where you said error is occurring) you will see that we're trying to index a key in a table that is nil. values[2]

This means that the variable values is nil. You cant index nil objects. Since values its self is nil we can trace back the problem to the declaration of values which is on line 3. local values = item_settings[parent]

This here is wrong

parent is using the name of the model and finds that same name in the module script

ROBLOX uses a datatype called a "userdata" for instances such as parts and such. When you're indexing item_settings[parent, it is looking for a key within the dictionary that has the key for the reference to the userdata parent and not the name of parent.

Solution

On line 3 which is local values = item_settings[parent]; replace item_settings[parent] with item_setings[parent.Name] so it will look for the string inside of the item_settings with parent's name instead of using the reference to the userdata.

Accept this answer if it helped!

0
Sorry ive already tried that and the result is the same ComplexCrypt -5 — 5y
0
this is the error in the output Workspace.Tycoons.Test_Tycoon.Ore_Storage.Ore.Dropper_Script:4: attempt to index local 'values' (a nil value) ComplexCrypt -5 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Sorry i found out what it was its because i had the dropper script in the drop part which i was cloning and using as the ore so i would have to edit all the brick color and stuff and it was running in the ore storage cause i forgot to delete the script in the ore before the ore spawned.

Answer this question