~Error Bandit (Boss) is not a valid member of Players
in Local "char =..."
Within the Bandits folder, there are several Bandits with the same name "Bandit", only 1 that is named "Bandit (Boss)"
I want to damage everyone not in the "ninfect" table.
I started using tables now.
01 | x.Touched:Connect( function (part) |
02 | if part.Parent:FindFirstChild( "Humanoid" ) = = nil then |
03 | else |
04 | if Player.Name ~ = part.Parent.Name then |
05 | local infect = { } |
06 | local ninfect = { } |
07 | table.insert(infect, part.Parent.Name) |
08 |
09 | for i, v in ipairs (infect) do |
10 | if part.Parent.Name ~ = table.concat(ninfect, "" ) then |
11 | local char = game.Players [ v ] .Character.Humanoid or game.Workspace.Map.Npcs.Bandits [ v ] .Humanoid |
12 | char.Health = char.Health - 90 |
13 | wait(. 5 ) |
14 | table.insert(ninfect, part.Parent.Name) |
15 | end |
16 | end |
17 | end |
18 | end |
19 | end ) |
I assume that "Player" has a value, otherwise you would not be attempting to call a nil value. I'm going to just assume you gave it a value and didn't tell us.
01 | x.Touched:Connect( function (part) |
02 | if not part.Parent:FindFirstChild( "Humanoid" ) then |
03 | else |
04 | if Player.Name ~ = part.Parent.Name then |
05 | local infect = { } |
06 | local ninfect = { } |
07 | table.insert(infect, part.Parent.Name) |
08 |
09 | for i, v in ipairs (infect) do |
10 | if not ninfect [ part.Parent.Name ] then |
11 | assert (v:IsA( "Player" ), "Did not receive a player object" ) -- Stops script if v is not a player |
12 | local char = game.Players [ v ] .Character.Humanoid or game.Workspace.Map.Npcs.Bandits [ v ] .Humanoid |
13 | char.Health = char.Health - 90 |
14 | wait(. 5 ) |
15 | table.insert(ninfect, part.Parent.Name) |
16 | end |
17 | end |
18 | end |
19 | end |
20 | end ) |
Not 100% sure what you were trying to do, but either way, I made some minor changes to make it easier to read.
also made a check that v is even a player