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

How do you make a BillboardGui show up only when you're near it?

Asked by
Exadide 15
4 years ago

I have this door system, where when you're near it I'd like for it to say "Press E to open." However, the GUI only shows up when you're near it with your camera, not your player. How do you make it so that the BillboardGui pops up only when your character is near it, not the camera?

2 answers

Log in to vote
0
Answered by 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

You have to use

.magnitude

Example script:

In a Local script:

local range = 20
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local Door = workspace.Door --You can have more than one door I think you have to use a loop then cuz I already made something like that .-.

local Door_Primary = Door.PrimaryPart

while true do
wait()
local distance = (hrp.Position - Door_Primary).magnitude
if distance <= range then
--Your code
end
end
Ad
Log in to vote
0
Answered by 4 years ago

Hello, Exadide. You don't even need a script. Just set the BilboardGui's "MaxDistance" property to the maximum distance you want. Please accept this answer and upvote it if it helped you.

Answer this question