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

How to damage who's on the table?

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

4 comments

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

0

Oh, I forgot that. wait

0

Line 11: attempt to index a nil value

0

With FindFirstChild(v)

1 answer

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

3 comments

0

attempt to call method 'IsA' (a nil value)

0

your script is finalizing if not a player, but I want npc too

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