Hello is there a way to manipulate the billboard gui to only be seen in a certain distance i have been researching and i can't find one even on Wiki?
note: i'm not asking to make one for me i just really need to know, If there is a way if it is i wanna know how.
In order to accomplish what you want, you gotta know some things about 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) --> 7.0710678100586 --^This is the length of the given vector
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) --First vector local v2 = Vector3.new(0,5,5) --Second vector local dist = v2 - v1 --Create another vector, of the difference between the two print(dist.magnitude); --Now get the distance of it, using magnitude. --> 11.180339813232
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.
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 --Clarify the distance limit repeat wait() until plr.Character --Wait for the character to load while wait(1) do --Check every second local pos1 = plr.Character:WaitForChild("Torso").Position local pos2 = yourGuisAdornee.Position --Change this local dist = (pos2 - pos1).magnitude if dist > limit then plr.PlayerGui.yourGui.Frame.Visible = false --Change this else plr.PlayerGui.yourGui.Frame.Visible = true --Change this end end
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 --code end end