In order to accomplish what you want, you gotta know some things about magnitude.
Magnitude
Magnitude is a member of Vector3's. If you get the magnitude of a vector, you're getting the length of that vector.
print(Vector3.new(0,5,5).magnitude)
So, why is this useful? Because you can subtract two vectors from eachother, creating a vector that is the length of the distance between them in the world space. Get the magnitude of that vector and you receive a number, in studs, approximately how far away the two vectors, or positions, are from eachother.
local v1 = Vector3.new(0,0,-5)
local v2 = Vector3.new(0,5,5)
local dist = v2 - v1
print(dist.magnitude);
So now the only question is what are your two positions going to be? One of them should be the character's torso, since this accurately represents where the character is located. The other should be the BillboardGui Adornee's position, since that accurately displays where the BillboardGui is positioned.
Code
So, the code would look something like this. Run this on the client. Use a localscript located in StarterGui. Edit line 6, 8, 11, and 13.
local plr = game.Players.LocalPlayer
local limit = 200
repeat wait() until plr.Character
while wait(1) do
local pos1 = plr.Character:WaitForChild("Torso").Position
local pos2 = yourGuisAdornee.Position
local dist = (pos2 - pos1).magnitude
if dist > limit then
plr.PlayerGui.yourGui.Frame.Visible = false
else
plr.PlayerGui.yourGui.Frame.Visible = true
end
end
Edit
If you want only a selected person to be able to see it disappear then you have to somehow declare who this person will be. This can be done by simply setting a variable tied to a string;
local seeIt = "Goulstem"
Alternatively, if you want a group of selected people to be chosen, you can create a table of strings;
local seeIt = {"Goulstem","iiAngelie123"}
Either way you do it, you're going to want to check who the LocalPlayer is. You can compare the LocalPlayer's name to the strings to check if they match. This would be done with the if statement along with checking the magnitude.
So, if it's a single string the if statement would look like this;
if dist > limit and seeIt == plr.Name then
If you're going the table way, you're going to want to iterate through the table. Then you compare each index.
for _,v in next,seeIt do
if dist > limit and v == plr.Name then
end
end
1 comment
Magnitude. My friend.