Hi there, I have a simple script that prints the magnitude between you and a random person. The issue is, is that the random person selected constantly changes if more than one person apart from you is in the server. I don’t know what else to try as I have no idea on why this could’ve had happened, but would like help regarding to it.
local Players = game:GetService("Players")
local players = {}
local PlayerPerson
local RandomPlayer
local function randomperson()
repeat
RandomPlayer = Players:GetPlayers()[math.random(#Players:GetPlayers())]
until RandomPlayer.Name ~= "vxsqi"
return RandomPlayer
end
local function LPlayer()
PlayerPerson = game:GetService('Players').vxsqi
return PlayerPerson
end
while true do
local pos = LPlayer().Character.HumanoidRootPart
local secondpos = randomperson().Character.HumanoidRootPart
local function mainperson()
local posx = tonumber(pos.Position.X)
local posy = tonumber(pos.Position.Y)
local posz = tonumber(pos.Position.Z)
local posxround = math.round(posx)
local posyround = math.round(posy)
local poszround = math.round(posz)
local vector = Vector3.new(posxround,posyround,poszround)
return vector
end
local function secondperson()
local posx = tonumber(secondpos.Position.X)
local posy = tonumber(secondpos.Position.Y)
local posz = tonumber(secondpos.Position.Z)
local posxround = math.round(posx)
local posyround = math.round(posy)
local poszround = math.round(posz)
local vector = Vector3.new(posxround,posyround,poszround)
return vector
end
local magnitude = (mainperson() - secondperson()).Magnitude
print("The magnitude between "..LPlayer().Name.." and "..randomperson().Name.." is "..magnitude..".")
if magnitude > 100 then
print("valid")
end
task.wait(1)
end