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

Making a table and retrieving and deleting objects?

Asked by 7 years ago
Edited 7 years ago

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)
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. marioblast1244 113 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

Answer this question