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

Attempt to index a nil value?

Asked by 5 years ago

When i buy a certain item with this script from a simulator-like shop, it gives me the error Attempt to index a nil value.

game.ReplicatedStorage.ShopBuy.OnServerEvent:Connect(function(player,page)
    local tool = game.ReplicatedStorage:WaitForChild("Tools")
    local shop = game.Workspace.Shop
    local clone = tool:FindFirstChild(shop:FindFirstChild("Part"..page).ItemName.Value):Clone() -- Breaks here
    local clone2 = tool:FindFirstChild(shop:FindFirstChild("Part"..page).ItemName.Value):Clone()
    clone.Parent = player.Backpack
    clone2.Parent = player.StarterGear -- So that the player won't lose the tool even if they died.
end)
0
you're looking for the shop in replicatedstorage, but we already know its in workspace.. Gey4Jesus69 2705 — 5y
0
The items are in the replicated storage, this script makes it so when the button is clicked, it adds the item to the players inventory, saves it there. The script is looking for the items in the replicated storage to add to the players backpack. RebornedInFire 35 — 5y
0
`Attempt to index a nil value` means either your code can't find it or it does not even exist. WideSteal321 773 — 5y
0
Thanks for telling me that, im gonna go try to fix it thanks. RebornedInFire 35 — 5y

Answer this question