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

Attempt to index nill with 'name'?

Asked by 3 years ago

so im making a shop and 'attempt to index nil with 'name'' keeps coming up

here is my code

    local ReplicatedStorage = game:GetService('ReplicatedStorage')
    local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')

    local function buyTool(player, tool)
local giveTool = ReplicatedStorage.ShopItems[tool.name]:Clone()
giveTool.Parent = player.Backpack

local giveTool = ReplicatedStorage.ShopItems[tool.name]:Clone()
giveTool.Parent = player.StarterGear
    end


    remoteEvent.OnServerEvent:Connect(buyTool)
0
From the error, I can tell that tool has a nil value. Can you edit your auestion and add the script that fires, this serverevent? JustinWe12 723 — 3y

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago
Edited 3 years ago

The problem is you didn't use name with a capital

Try this

local ReplicatedStorage = game:GetService('ReplicatedStorage') 
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')

local function buyTool(player, tool)
    local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()
    giveTool.Parent = player.Backpack

    local giveTool2 = ReplicatedStorage.ShopItems[tool.Name]:Clone()
    giveTool2.Parent = player.StarterGear
end


remoteEvent.OnServerEvent:Connect(buyTool)
0
Please Accept my answer if it works MattVSNNL 620 — 3y
0
i tried it with capitals still dont work MotherMotherRun -5 — 3y
0
Try givetool 2 because you already have one MattVSNNL 620 — 3y
0
still wont work MotherMotherRun -5 — 3y
View all comments (7 more)
0
Lemme see the script where you fire the event MattVSNNL 620 — 3y
0
wdym? im new to scripting, im following a tuorial MotherMotherRun -5 — 3y
0
Who are you watching MattVSNNL 620 — 3y
0
im at 39:00 MotherMotherRun -5 — 3y
0
Try this one MattVSNNL 620 — 3y
Ad

Answer this question