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

Why the value 3 is not detected ?

Asked by 3 years ago
Edited 3 years ago

the pistol3 is next why ? (It's for a unlock the next item to buy)

This is a video with the bug https://www.youtube.com/watch?v=bCXXtnPLcVI

local Player = game.Players.LocalPlayer
local ReplicatedStorage = game.ReplicatedStorage


script.Parent.MouseButton1Click:Connect(function()
    if script.Parent.Parent.PetInventory.Visible == false then
        script.Parent.Parent.PetInventory.Visible = true


        local inventory = script.Parent.Parent.PetInventory.Inventory.InventoryFrame
        local plritem = Player:FindFirstChild("Items"):GetChildren()
        local itemfolder = ReplicatedStorage:FindFirstChild("Items"):GetChildren()
        for i = 1,#plritem do
            for j = 1,#itemfolder do
                if plritem[i].Name == itemfolder[j].Name then
                    print(plritem[i].Name, itemfolder[j+1].Name)
                    local item = inventory:FindFirstChild(itemfolder[j+1].Name)
                    item.Background.Locked.Visible = false
                end
            end
        end


    else
        script.Parent.Parent.PetInventory.Visible = false
    end
end)

19:29:19.471 - Players.xDZweird.PlayerGui.Shop.PetInventoryButton.LocalScript:16: attempt to index nil with 'Name' 19:29:19.472 - Stack Begin 19:29:19.472 - Script 'Players.xDZweird.PlayerGui.Shop.PetInventoryButton.LocalScript', Line 16 19:29:19.473 - Stack End Pistol Pistol2 Pistol2 Pistol3 Pistol4 Pistol5 Pistol5 Pistol6

0
It would seem itemfolder[j+1] is nil. You're looping as many times as there are items in the table itemfolder. Therefore on the last iteration, itemfolder[j] would be the last thing in the table, yet you try to index it with j+1 which does not exist. cowsoncows 951 — 3y
0
Thank you for your answer, so how to buy an item you have to buy the previous one xDZweird 5 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

I don't know if this is going to work, or if this is even the problem, but here I go. Let's say you have the following table:

local players = {
    player1 = "BrodyGamer101";
    player2 = "xDZweird";
    player3 = "Aiden16026"

}

If you try to access each value as:

players[number]

It won't work. It will be nil. Instead, you have to change the table to be like:

local players = {
    "BrodyGamer101";
    "xDZweird";
    "Aiden16026"

}

Then you can do

players[number]

Like I said, I have no idea if this is even relevant, but it's a good tip to all you out there.

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

When you buy one item a boolvalue is create with the name of the item, it is plritem in the script. It is a folder in plr

Answer this question