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

Attempt to index nil with 'Name' What does this mean?

Asked by 4 years ago
local function partTouched(onTouch)
    local tool = game.Players:FindFirstChild("Tool")
    if tool.Name == "Sword" then
        tool:Destroy()
    end
end

script.Parent.Touched:Connect(partTouched)

I made this script to remove your sword when you touch this part It doesn't work for some reason and here is the output error:

11:30:44.415 - Workspace.Part.Script:3: attempt to index nil with 'Name'

0
are you sure there is a tool in players? Dan_PanMan 227 — 4y
0
yes i put a tool in starterpack which should mean theres one in the backpack of the player ScriptsALot 91 — 4y
0
then you do local tool = game.Palyers.Backpack:FindFirstChild("Tool") Dan_PanMan 227 — 4y
0
players* Dan_PanMan 227 — 4y
View all comments (5 more)
0
i dont think you understand where the backpack is ScriptsALot 91 — 4y
0
script.Parent.Touched:connect(function(p) if p.Parent.Name == "Key" then p.Parent:Destroy() end end) JailBreaker_13 350 — 4y
0
bruh backpack is in the localplayer that is in players Dan_PanMan 227 — 4y
0
That can do it if they are holding the tool. JailBreaker_13 350 — 4y
0
yes but you cant say game.Players.backpack lol ScriptsALot 91 — 4y

2 answers

Log in to vote
3
Answered by
AspectW 431 Moderation Voter
4 years ago
Edited 4 years ago

In your case, it means that "tool" does not exist. Also, tools go inside the player's backpack, not inside the player object. I assume your code should look something like this below.

local function partTouched(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player then
        local tool = player.Backpack:FindFirstChild("Sword")
        if tool then
             tool:Destroy()
        end
    end
end

script.Parent.Touched:Connect(partTouched)
Ad
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

It means your trying to check for a name and trying to change the name to that specific name to fix this try:


local function partTouched(onTouch) local player = game.Players.LocalPlayer local Tool = player.Backpack:FindFirstChild("Tool") --Find the tool name if Tool then if Tool.Name == "Sword" then tool:Destroy() end end end end script.Parent.Touched:Connect(partTouched)
0
so much errors in your code bruh Dan_PanMan 227 — 4y
0
Im on mobile. JesseSong 3916 — 4y
0
so? mobile users can type well too Dan_PanMan 227 — 4y
0
Whats wrong with it? JesseSong 3916 — 4y
View all comments (4 more)
0
A backpack is not inside the player service, it is inside the local player. JailBreaker_13 350 — 4y
0
Like I said Im on mobile so its hard for me to check for errors. JesseSong 3916 — 4y
0
Ofc i know that JesseSong 3916 — 4y
0
You are checking for a child of backpack with the name "Tool" and then you are checking if the child's name is "Sword"? AspectW 431 — 4y

Answer this question