How do you make a gui's adornee go on a part that is closest to you and at least 10 studs away?
I'm trying to make a gui's adornee on a part that is spawned by someone when they click a button. Also, the person who spawned the part is the only one who can see the gui on that part.
The gui will only pop up if the part is the closest to the player that spawned it and is ten studs away.
I tried doing this:
01 | local plrName = script.Parent.Name |
02 | local rK = game.Players:GetPlayerFromCharacter(script.Parent).PlayerGui:WaitForChild( "RKeyGen" ) |
05 | for i, v in pairs (game.Workspace.Bricks:GetChildren()) do |
06 | if v.Name = = plrName then |
07 | local pPos = v.Position |
08 | local lPos = script.Parent:FindFirstChild( "HumanoidRootPart" ).Position |
09 | local pAvg = (pPos.X + pPos.Y + pPos.Z)/ 3 |
10 | local lAvg = (lPos.X + lPos.Y + lPos.Z)/ 3 |
11 | local sAway = math.abs(pAvg - lAvg) |
12 | v.NumVal.Value = sAway |
16 | for i, v in pairs (game.Workspace.Bricks:GetChildren()) do |
17 | if v.Name = = plrName then |
19 | if v.NumVal.Value > n and v.NumVal.Value < 10 then |
But, the gui just pops up even when theres other parts closest to me and it stays on the same part even when i am like, 30 studs away from it.
Any help?