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 nill with 'name'?

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)

1 comment

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?

1 answer

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)

11 comments

0

Please Accept my answer if it works

0

i tried it with capitals still dont work

0

Try givetool 2 because you already have one

0

still wont work

0

Lemme see the script where you fire the event

0

wdym? im new to scripting, im following a tuorial

0

Who are you watching

0

im at 39:00

0

Try this one

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