My script keeps giving me the error " attempt to index field ‘?’ (a nil value)"
Here’s the script that makes the cookvalue, etc
Am I doing something wrong? It’s gonna be for cooking items in my upcoming survival game
Script is below
local items = {
["cookthing"] = {
cooksTo = {
name = "EpicPart",
steps = 30,
}
}
}
while wait() do
for _,item in pairs(game.Workspace:GetDescendants()) do
local cv = item:FindFirstChild("CookValue")
if cv then
if cv.Value == items[item.Name].cooksTo.steps then
local cframe = item.CFrame
local superPart = game:GetService("ReplicatedStorage"):FindFirstChild(items[item.Name].cooksTo.name)
local epicpart = superPart:Clone()
epicpart.Anchored = true
epicpart.CFrame = cframe
epicpart.Parent = workspace
item:Destroy()
end
end
end
end```
Yeah, I have a script that begins the cooking, here
local items = {
["cookthing"] = {
cooksTo = {
name = "EpicPart",
steps = 30,
}
}
}
function objPosition(pos1,pos2,studs)
if pos1.Position.Magnitude - pos2.Position.Magnitude <= studs then
return true
else
return
end
end
while wait(1) do
for _,item in pairs(game.Workspace:GetDescendants()) do
if item.Name ~= "Campfire" and item:IsA("BasePart") then
if objPosition(script.Parent, item, 5) then
local itemCook = item:FindFirstChild("CookValue")
if not itemCook then
local cv = Instance.new("IntValue", item)
cv.Name = "CookValue"
cv.Value = cv.Value + 1
itemCook = cv
else
itemCook.Value = itemCook.Value + 1
end
end
end
end
end
local items = {
["cookthing"] = {
cooksTo = {
name = "EpicPart",
steps = 30
}
}
}
while wait() do
for _,item in pairs(game.Workspace:GetDescendants()) do
local cv = item:FindFirstChild("CookValue")
if cv then
if items[item.Name] then
if cv.Value == items[item.Name]['cooksTo']['steps'] then
local cframe = item.CFrame
local superPart = game:GetService("ReplicatedStorage"):FindFirstChild(items[item.Name].cooksTo.name)
local epicpart = superPart:Clone()
epicpart.Anchored = true
epicpart.CFrame = cframe
epicpart.Parent = workspace
item:Destroy()
end
end
end
end
end