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'
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)
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)