How can I receive all players instead of using localplayer to receive one? For a AI!

Im using a ACS Ai,

local allies = {script.Parent.Name, "Afghan,Child","Afghan_Civi"}

Here is where I insert allies so it won’t shoot them, but I want to add a and statement like this:

local allies = {script.Parent.Name, "Afghan,Child","Afghan_Civi"} and {game.Players}

but game.players will not work, as then it won’t shoot anything
Please help.

When does this script go off, and do you need the list of players to be constantly updated?

Not constantly, but everytime someone leaves/joins/resets.

The script goes off when people are in 100 stud distance.

Will this work though?(Edit: no it doesn’t, the ai just won’t shoot)

local allies = {script.Parent.Name, "Afghan,Child","Afghan_Civi"} and {game.Players:GetPlayers()}

I’ve never used this method before. “The one that you are trying to use”
But if you really want all players in the game in one list, then I would just make a function that adds a player to the list or deletes them when they leave or join the game.
If you don’t know how to do this, I can make a mock script.

I don’t know how to do this…
I’m more of a starter.

1 Like

Try this out

local Allies = {}


function RefreshAllyList(plr)
	if table.find(Allies,plr) then	
		table.remove(Allies,table.find(Allies,plr))
	else
		table.insert(Allies,plr)
	end
	print(Allies)
end

game.Players.PlayerAdded:Connect(RefreshAllyList)
game.Players.PlayerRemoving:Connect(RefreshAllyList)

This should notice when a player is added or remove from the game, then try to update the list

I think I have the refreshing part is down, just I need it to get all the players in the game(instead of localplayer which is one player) and make them into the ally list.

Did the script not work? this should check when ever a player is added and put them in the list

I mean I already have the part where it refreshes. just I need it to get all the players in the game(instead of localplayer which is one player) and make them into the ally list.
This is the part I’m having trouble on.

I’m pretty sure this gets all the players in the game, did you already test it out?

1 Like

Wait I got it:

local function getPlayerNames()
    local result = players:GetPlayers()

    for index, player in result do
        result[index] = player.Name
    end

    return result
end
local allies = {script.Parent.Name, "Afghan,Child","Afghan_Civi", table.unpack(getPlayerNames())}

This what I just posted solved it. I was looking at how to get it on youtube, your script did work just it was hard to configure with my ai. But thank you so much for trying!

Okay, that’s good. I’ve actually used this script many times in my Ai, wish I knew this was what you were looking for.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.