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

How come this script wont work?

Asked by 8 years ago

How come this script doesnt work?

potatoes = nil

function mash_potatoes(softness)
for i, v in pairs(potatoes) do 
if v.Softness < softness then
v.Mashedness.Value = v.Mashedness.Value-1
end
end
end

mash_potatoes(1)
0
error line 04 attempting to index a nil value User#5978 25 — 8y
0
Because you set potatoes as nil on line 1... Should be a table value. M39a9am3R 3210 — 8y
0
oh User#5978 25 — 8y
0
wtfffff i come back to this Redbullusa 1580 — 8y
0
this basically visualizes indexing a nil value... HungryJaffer 1246 — 8y

1 answer

Log in to vote
2
Answered by
4Bros 550 Moderation Voter
8 years ago

Ok, it seems that you want to iterate through a table called potatoes but you indexed potatoes as a nil value. potatoes should refer to a table with another table inside it containing two properties called Softness and Mashedness. From the looks of it, Mashedness should be a NumberValue. You should also change the context of potatoes to local instead of having it global.



local potatoes = { potato ={ Softness = 0, Mashedness = Instance.new("NumberValue",game:GetService'Workspace') } } function mash_potatoes(softness) for i, v in pairs(potatoes) do if v.Softness < softness then v.Mashedness.Value = v.Mashedness.Value-1 end end end mash_potatoes(1)
1
hash slinging slasher slashes User#5978 25 — 8y
Ad

Answer this question