Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a table and retrieving and deleting objects?

I made a table which includes weapons. When the parent of this script is clicked, I want to remove these tool(s) if they are present inside of the player in workspace. When I press the button, nothing happens. I'm new to tables so help would be appreciated.

local player = game.Players.LocalPlayer
local character = player.Character


function onClick()
local weapons = {
	[character.M14] = "M14",  
	[character.G36K] = "G36K",
	[character.Patriot] = "Patriot",
}

if character:FindFirstChild(weapons) then
	weapons:Destroy()
end
end
script.Parent.MouseButton1Down:connect(onClick)

1 comment

0

The only way that I can think of is actually listing all of the weapons as different variables, but that will take too long.

1 answer

✓ Accepted answer

You are already calling the character from the table as well as outside of the table, which causes it to be very confusing.

Maybe try this.

local player = game.Players.LocalPlayer
local character = player.Character


function onClick()
  local weapons = {
   	"M14",  
   	"G36K",
	"Patriot",
  }

for i=1, #weapons do
    local item = character:FindFirstChild(weapons[i])
  	if item then
    	item:Destroy()
  	end
  end
end

script.Parent.MouseButton1Down:connect(onClick)

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