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

Attempt to index local 'item' (a nil value) error but only outside of studio?

Asked by
Sekant 20
7 years ago

The error given is: Workspace.REventHandler:3: attempt to index local 'item' (a nil value)

Local Script which defines item "selectedItem's value is set to 1 and there is always a child in foundation"

local items = game.Lighting.items:WaitForChild("foundation"):GetChildren()
local item = items[stat:WaitForChild("selectedItem").Value]:Clone()

mouse.Button1Down:connect(function()
    if stat.isValid.Value == true then
        evt.build:FireServer(item:GetPrimaryPartCFrame(),                                       
                items[stat.selectedItem.Value]:Clone())
    end
end)
game.ReplicatedStorage.REvents.build.OnServerEvent:connect(function(plr, cframe, item)  

    item:SetPrimaryPartCFrame(cframe)
    item.Parent = workspace.targetFilter.building

end)
1
Try this: items:WaitForChild(stat:WaitForChild("selectedItem").Value) Programical 653 — 7y
1
And don't use lighting for storage. Programical 653 — 7y
0
Those things are not loaded when localscript begins so use WaitForChild. cabbler 1942 — 7y

Answer this question