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

How to damage who's on the table?

Asked by 4 years ago

~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.

x.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") == nil then
else
    if Player.Name ~= part.Parent.Name then
    local infect  = {}
    local ninfect = {}  
    table.insert(infect, part.Parent.Name)

    for i, v in ipairs(infect) do
        if part.Parent.Name ~= table.concat(ninfect, "") then
            local char = game.Players[v].Character.Humanoid or game.Workspace.Map.Npcs.Bandits[v].Humanoid
            char.Health = char.Health - 90
            wait(.5)
        table.insert(ninfect, part.Parent.Name)
            end
         end
      end
   end
end)
0
you're assuming that [v] is already a player model. use findfirstchild to check if the model name is actually a player before experimenting with it Fifkee 2017 — 4y
0
Oh, I forgot that. wait ToddyWars 41 — 4y
0
Line 11: attempt to index a nil value ToddyWars 41 — 4y
0
With FindFirstChild(v) ToddyWars 41 — 4y

1 answer

Log in to vote
0
Answered by
commag 228 Moderation Voter
4 years ago

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.

x.Touched:Connect(function(part)
if not part.Parent:FindFirstChild("Humanoid") then
else
    if Player.Name ~= part.Parent.Name then
    local infect  = {}
    local ninfect = {} 
    table.insert(infect, part.Parent.Name)

    for i, v in ipairs(infect) do
        if not ninfect[part.Parent.Name] then
        assert(v:IsA("Player"), "Did not receive a player object") -- Stops script if v is not a player
            local char = game.Players[v].Character.Humanoid or game.Workspace.Map.Npcs.Bandits[v].Humanoid
            char.Health = char.Health - 90
            wait(.5)
        table.insert(ninfect, part.Parent.Name)
            end
         end
      end
   end
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

0
attempt to call method 'IsA' (a nil value) ToddyWars 41 — 4y
0
your script is finalizing if not a player, but I want npc too ToddyWars 41 — 4y
Ad

Answer this question