So your right that it will involve magnitude but it also requires a few things so i am going to walk you through what you need to add to make it work like you want.
The Problem
so we want a billboard gui that is visible locally meaning only the player can see it. To achieve this we need to use local parts which can be created by setting filtering enabled to true then creating the gui from the client.
The Script
so to start lets make filtering enabled = true. this will allow for local parts. now lets create a function that will make the gui so we can use it later
01 | function createNewGui(newPlayer) |
02 | local Gui = Instance.new( "BillboardGui" ) |
03 | Gui.Parent = newPlayer.Character.Head |
04 | Gui.Adornee = newPlayer.Character.Head |
05 | Gui.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
06 | Gui.StudsOffset = Vector 3. new( 0 , 2 , 0 ) |
08 | local Text = Instance.new( "TextLabel" ) |
09 | Text.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
10 | Text.BackgroundTransparency = 1 |
11 | Text.TextColor 3 = Color 3. new( 230 / 255 , 0 / 255 , 0 / 255 ) |
12 | Text.TextStrokeTransparency = 0 |
13 | Text.TextTransparency = 0 |
14 | Text.FontSize = "Size18" |
15 | Text.Font = "ArialBold" |
17 | local Rank = "[Tag Name]" |
18 | local Person = newPlayer.Name |
simple enough so now onto your initial problem giving each player a distance limiter. to do this we can create another function called check distance
03 | function checkDistance(player 1 , player 2 ) |
04 | local character 1 = player 1. Character |
05 | local character 2 = player 2. Character |
06 | if (character 1. Torso.Position - character 2. Torso.Position).magnitude < = maxDistance then |
10 | local trash = player 2. Character.Head:FindFirstChild( 'BillboardGui' ) |
next i am going to set up a while true do loop. what this loop will do is loop through every player and run it through our checkDistance function which calls our createNewGui function
01 | local me = game.Players.LocalPlayer |
05 | while wait( 1 /renderTime) do |
06 | for i, v in pairs (game.Players:GetPlayers()) do |
07 | if v.Name ~ = me.Name then |
and that would be your loop so we can combine everything here to come up with this
Final Product
01 | local me = game.Players.LocalPlayer |
05 | function createNewGui(newPlayer) |
06 | local Gui = Instance.new( "BillboardGui" ) |
07 | Gui.Parent = newPlayer.Character.Head |
08 | Gui.Adornee = newPlayer.Character.Head |
09 | Gui.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
10 | Gui.StudsOffset = Vector 3. new( 0 , 2 , 0 ) |
12 | local Text = Instance.new( "TextLabel" ) |
13 | Text.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
14 | Text.BackgroundTransparency = 1 |
15 | Text.TextColor 3 = Color 3. new( 230 / 255 , 0 / 255 , 0 / 255 ) |
16 | Text.TextStrokeTransparency = 0 |
17 | Text.TextTransparency = 0 |
18 | Text.FontSize = "Size18" |
19 | Text.Font = "ArialBold" |
21 | local Rank = "[Tag Name]" |
22 | local Person = newPlayer.Name |
27 | function checkDistance(player 1 , player 2 ) |
28 | local character 1 = player 1. Character |
29 | local character 2 = player 2. Character |
30 | if (character 1. Torso.Position - character 2. Torso.Position).magnitude < = maxDistance then |
34 | local trash = player 2. Character.Head:FindFirstChild( 'BillboardGui' ) |
42 | while wait( 1 /renderTime) do |
43 | for i, v in pairs (game.Players:GetPlayers()) do |
44 | if v.Name ~ = me.Name then |
hope this helped remember to set filtering enabled to true otherwise it wont work