I want this loop to ignore the local player and get everyone else.
It keeps getting everyone including the local player
I’ve tried different things but they just broke the script.
for _,v in pairs (game.Players:GetChildren()) do
local Distance = (v.Character.Torso.Position-player.Character.Torso.Position).Magnitude
if Distance < range then
local victims = v
move_type = "Crows"
genjutsu:FireServer(move_type,victims)
else
Another fancy way to do it is, since this line exists:
local Distance = (v.Character.Torso.Position-player.Character.Torso.Position).Magnitude
If the current v was indeed the local player, then technically the distance between the local player and himself is gonna be 0. You can simply check if the distance is also ~= to 0.
It’s better to compare player objects than their names. Comparing names is a string comparison which is slower than object comparison which checks if the references point to the same object.
Apart from the technical difference, the code is cleaner because logically: comparing player objects is enough, adding names doesn’t change anything in terms of the outcome.
local players = game:GetService("Players")
local victims = players:GetPlayers()
I = table.find(victims, players.LocalPlayer)
table.remove(victims, I)
for _, player in ipairs (victims) do
genjutsu:FireServer("Crows", player)
-- will fire the event for everyone other than the Local Player
end
However it could be as simple as only firing for the Local Player and on the server, exempting him from the victims list.
I doubt that would happen, unless the game disables character cancolliding. But even if that’s the case, there definitely would be a very tiny friction, which would still not be equal to 0
I’m trying to make my character turn invisible to people within range when I activate this move. But the player that uses this move also turns invisible on their screen. This script goes to the server then back to a local script which is supposed to make the user invisible for players within the range.
My point is, that although it is extremely unlikely, it COULD happen. And on a seperate note, comparing distance to find if it’s the local player is simply unnecessary, it’s a waste of processing power and is just a wierd way to go about it.
Simply append an if statement to your for loop to ensure the player is not the LocalPlayer:
local Players = game:GetService("Players");
local LOCAL_PLAYER = Players.LocalPlayer;
...
for _,player in ipairs(Players:GetPlayers()) do --Always use :GetPlayers()
if player ~= LOCAL_PLAYER then -Making sure the player is NOT the LocalPlayer
--Your code here
end
end