Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Billboard gui can only be seen in a certain distance?

Asked by 8 years ago

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.

0
Magnitude. My friend. rexbit 707 — 8y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)
--> 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.


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 --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

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
        --code
    end
end
0
Alright! thank you! i never heard magnitudes before but i gotta look more in the future on this kinds of stuff! thank you again! iiAngelie123 40 — 8y
0
Alright, one more question is there a way also just u to see it disappear? and everyone else too do the same thing? iiAngelie123 40 — 8y
0
Like only one selected person sees it disappear? Goulstem 8144 — 8y
0
Yes! thats it iiAngelie123 40 — 8y
View all comments (2 more)
0
Edited Goulstem 8144 — 8y
0
Alright thanks :) very helpful! iiAngelie123 40 — 8y
Ad

Answer this question