Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index nil with 'Item' Help?

I have a inventory gui that I am making so you can move to "Sort" your inventory. It will not work, It always errors. Here is the script (Normal script inside text button):

local MovingInventory = script.Parent.Parent.Parent.Parent.Parent.MovingInventory
local SlotMoving = script.Parent.Parent.Parent.Parent.Parent.MovingInventory

script.Parent.MouseButton1Click:Connect(function()
    if MovingInventory.Value == false then
        MovingInventory.Value = true
        SlotMoving.Value = script.Parent.Name
    elseif MovingInventory.Value == true then
        MovingInventory.Value = false
        game.ReplicatedStorage.Values:WaitForChild("Item").Value = script.Parent.Parent:FindFirstChild(SlotMoving.Value).Item.Value
        game.ReplicatedStorage.Values:WaitForChild("Amount").Value = script.Parent.Parent:FindFirstChild(SlotMoving.Value).Amount.Value
        script.Parent.Item.Value = script.Parent.Parent:FindFirstChild(SlotMoving.Value).Item.Value
        script.Parent.Amount.Value = script.Parent.Parent:FindFirstChild(SlotMoving.Value).Amount.Value
        script.Parent.Parent:FindFirstChild(SlotMoving.Value).Item.Value = game.ReplicatedStorage.Values.Item.Value
        script.Parent.Parent:FindFirstChild(SlotMoving.Value).Amount.Value = game.ReplicatedStorage.Values.Amount.Value
    end
end)

Thanks!

2 comments

0

(sorry if it is sloppy, this is a repost since nobody answered the original question within a month.)

0

Whats the error and on what line it occurs?

1 answer

Your script errors, as one of your FindFirstChild returns nil, meaning it has not found what you tasked it with finding. Which one exactly is erroring, I cannot say, as you did not provide your output and which line is causing issues. What I can suggest though, is to clean up your code a bit:

local MovingInventory = script.Parent.Parent.Parent.Parent.Parent.MovingInventory
local SlotMoving = script.Parent.Parent.Parent.Parent.Parent.MovingInventory
local Item =  game.ReplicatedStorage.Values:WaitForChild("Item")
local Amount = game.ReplicatedStorage.Values:WaitForChild("Amount")

script.Parent.MouseButton1Click:Connect(function()
    if MovingInventory.Value == false then
        MovingInventory.Value = true
        SlotMoving.Value = script.Parent.Name
    elseif MovingInventory.Value == true then
	local Slot = script.Parent.Parent:FindFirstChild(SlotMoving.Value)
	if not Slot then
		warn("Slot not found")
		return
	end
        MovingInventory.Value = false
        Item.Value =Slot.Item.Value
        Amount.Value = Slot.Amount.Value
        script.Parent.Item.Value =Slot.Item.Value
        script.Parent.Amount.Value = Slot.Amount.Value
        Slot.Item.Value = Item.Value
        Slot.Amount.Value = Amount.Value
    end
end)

Hope this helps.

1 comment

0

Thanks, i worked it out, i closed then question down the other day, not sure why it didnt save.

This discussion is preserved as it was. New answers, comments, and votes are closed.