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

What's wrong with my damage script?

Asked by
neoG457 315 Moderation Voter
8 years ago

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.

0
Is it just me, or does the way this is tabbed out annoy you? AZDev 590 — 8y
0
Thanks for the great answer, helped alot! neoG457 315 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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!

0
It says: (Connect is not a valid member) on line 6 ;-; neoG457 315 — 8y
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. alphawolvess 1784 — 8y
0
Yes, the lowercase c worked and so does the rest of the script, Thank You! neoG457 315 — 8y
0
Okay, I just capitalized it like you, I always do it lowercased but I didn't think it mattered. alphawolvess 1784 — 8y
Ad

Answer this question