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

What's wrong with my damage script?

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.

2 comments

0

Is it just me, or does the way this is tabbed out annoy you?

0

Thanks for the great answer, helped alot!

1 answer

✓ Accepted answer

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!

4 comments

0

It says: (Connect is not a valid member) on line 6 ;-;

0

Did you make a variable for everything in the table to be the part? I made connect lowercase but I don't know if that matters.

0

Yes, the lowercase c worked and so does the rest of the script, Thank You!

0

Okay, I just capitalized it like you, I always do it lowercased but I didn't think it mattered.

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