How would you check if the player is within the max distance of a BillboardGui?

Hey! So I am making a pet hatching solution since some of the players are having a hard time figuring out how to purchase an egg from the egg dispenser (You would click the sign to buy but a lot of players were confused on that). But anyways, how would I be able to check if the player is within the max distance of a Billboard Gui? Basically for example, if you were far away from some part that had a Billboard Gui, you probably would not be able to see it if it isn’t set to infinite. But if you were, you would see the Gui, meaning that you are near the part. I am trying to figure out a way to check if they are in the vicinity of the part. Thank you for helping me.

NOTE: context image in case it might help you:

Nevermind, I fixed it. I had to find if the player was within the range of the adornee position and the magnitude and such.

Here is the script if anyone else is having trouble with this as I only found one post without a solution:

local userinputservice = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded.Wait()
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")
local adornee = script.Parent.Adornee

userinputservice.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		local magnitude = (humanoidrootpart.Position - adornee.Position).Magnitude
		if magnitude <= 25 then
			game.ReplicatedStorage.BuyEgg:FireServer(player)
		end
	end
end)
2 Likes