I'm trying to inflict damage when any one of the parts in the table called "ID1Parts" is touched. LSeg1 etc are all normal parts.
When I try to do this it prints an error:
Players.Player.Backpack.DamageScript:5: invalid value (userdata) at index 1 in table for 'concat'
ID1Parts = {LSeg1, LSeg2, LSeg3, LSeg4, LSeg5} debounce = false table.concat(ID1Parts).Touched:Connect(function(part) local Human = part:FindFirstChild("Humanoid") if Human and not debounce and part.Parent ~= Player.Character then debounce = true Human:TakeDamage(10) end end)
I don't know why this happens, I've checked the wiki and have no idea. Please Help.
You cannot use table.concat()
to get objects from a table and make a touched event out of it. First, I will tell you what table.concat()
does. This will get your table, which is the first argument, and with everything in it, put it as a string with whatever you want to space each out. All things must either be a string or number. So, if your table was just Table = {"The", "Cat"}
and you printed table.concat(Table, "SPACE"), then the output will be "TheSPACECat because you chose SPACE to be in between each, if you're confused you can view the wiki (Which I think is more confusing about this topic) here for table.concat()
Now, I will ASSUME that your tables contents are all objects and you have a variable somewhere that give the object, example, local LSeg1 = game.Workspace.LSeg1
, and so on.
Now that your Table is all object, we can Iterate through this table using a generic for loop and connect them all to a touched event. Please look at some commenting for some more information on what I'm doing! Also, you may want to work on tabing your code correctly, if you don't know how, just comment.
ID1Parts = {LSeg1, LSeg2, LSeg3, LSeg4, LSeg5} -- Assuming all are variable of an actual part!! debounce = false for _, aPartInTable in pairs(ID1Parts) do -- Lets get each part, aPartInTable is a Part aPartInTable.Touched:connect(function(part) local Human = part.Parent:FindFirstChild("Humanoid") -- This was wrong, you looked for Humanoid inside of a part, Humanoid is under Character, not under a part inside of it! if Human and not debounce then -- No Idea what Player.Character is being used for so I removed it debounce = true Human:TakeDamage(10) -- If you do not make debounce = false here, this will never work after the first damage, I do not know if you wanted this or not so I didn't add it. end end) end
If this helped, accept the answer and if you have questions, just comment on this answer!