How would I make a variable for all the players except me and make a variable for my character?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to figure out how to make a variable for all of the players except the local player, or the player who fired the script. Its basically for a detection system to detect if someone is strong or not. It’ll look something like this system, but with an actual enemy player’s character.
    Video:

  2. What is the issue? Include screenshots / videos if possible!
    I’m having trouble figuring out a way to make a variable for my player and the rest of players, likewise with my character, and the rest of the character.
    image

SERVERSCRIPT:


-- Import our services
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")


-- Identify our target for use in the function below



-- Variables
local players = game:GetService("Players")
local playersTable = players:GetPlayers()
local plr = players.LocalPlayer
local MyCharacter = plr.Character or plr.CharacterAdded:Wait()

for i,player in pairs(playersTable) do
	if player.Name ~= plr.Name then continue end
	table.remove(playersTable,i)
	EnemyCharacter = player.Character
	EnemyCharacterRootPart = EnemyCharacter.HumanoidRootPart
	break
end

--Making sure MyPlayer Is excluded from the rest

-- This is not technically needed, but it is likely preferable as we do not want to our player model obscuring the part
-- to count as an obstruction.


local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = {MyCharacter}

local Camera = workspace.CurrentCamera
local TargetOnScreen = false
local TargetVisible = false

-- Primary function
local function checkIfPartIsOnScreen(EnemyHMRP)
	-- Use :WorldToViewportPoint
	local _, IsOnScreen = Camera:WorldToViewportPoint(EnemyHMRP.Position)

	-- Check if our target is on screen, and update our variable informing us if it is.
	if IsOnScreen and (not TargetOnScreen) then
		TargetOnScreen = true
		print("The target is now in our FOV!")
		-- Do the same, but in reverse
	elseif (not IsOnScreen) and TargetOnScreen then
		TargetOnScreen = false
		-- If the target is off screen, then the target must also not be visible.
		TargetVisible = false
		print("The target is no longer in our FOV.")
	end

	-- We don't need to perform a raycast check if the target is out of our FOV
	if TargetOnScreen then

		-- This may be confusing, but it is Vector3 math. It is getting the direction between our Camera and the part.
		local Direction = (EnemyCharacterRootPart.Position - Camera.CFrame.Position).Unit

		-- This 200 could be customized to set a specific range that you are checking for the player in, though performing
		-- a separate magnitude check beforehand will likely be more optimized.
		local RaycastResult = workspace:Raycast(Camera.CFrame.Position, Direction * 200, RaycastParameters)

		-- Check if our part was not hit by our Raycast check!
		if (not RaycastResult) or RaycastResult.Instance ~= EnemyCharacterRootPart then
			-- Now that we know that the target is obscured, we need to check if we need to output!
			if TargetVisible then
				TargetVisible = false
				print("The target is now obscured.")
			end
		else
			-- If the above is not true, we can see the target.
			if (not TargetVisible) then
				TargetVisible = true
				print("The target is visible.")
			end
		end
	end
end

-- Run our check every frame, you may want to not do this depending on how much you are running with this check.
RunService.RenderStepped:Connect(function()
	checkIfPartIsOnScreen(EnemyCharacterRootPart)
end)

You cannot get LocalPlayer from a server script, only from a LocalScript. In which case you can get a table of all the players except the LocalPlayer:

local players = game:GetService("Players")
local otherPlayers = {}

for i, player in game:GetService("Players"):GetChildren() do
	if player ~= players.LocalPlayer then
		table.insert(otherPlayers, player)
	end
end

--otherPlayers lists all players except the LocalPlayer

You could thread every player in sequence.


local function findPlayers()
     local tbl = game.Players:GetPlayers() or nil
     if tbl ~= nil then return tbl 
end
 
local Players = nil

game.Players.PlayerAdded:Connect(function()
     Players = findPlayers()
end)

The issue is that you are not assigning the EnemyCharacter and EnemyCharacterRootPart variables correctly. You are currently looping through the players table and removing the local player, but you are not assigning EnemyCharacter or EnemyCharacterRootPart to the player you want to target.

To fix this, you need to add a line of code in the loop that assigns EnemyCharacter and EnemyCharacterRootPart to the player you want to target. You can do this by adding this line of code:

EnemyCharacter = player.Character
EnemyCharacterRootPart = EnemyCharacter.HumanoidRootPart

Hope this helps!