✓ Accepted answer
Use magnitude
Example:
local player = game.Players.LocalPlayer
local char = player.Character
if (char.Torso.Position - workspace.Door.Position).magnitude >=5 then
player.PlayerGui.ScreenGui.Frame.Visible = true
end
To make the door open after this GUI is shown, simply use
UserInputService
And whenever the key to open the door (let's say E), then check if the Frame is visible, and if it is, you can then create your own things.
I'll teach you how this service works, so you know next time, it helps a lot.
We'll start by obtaining this service.
local UIS = game:GetService("UserInputService")
function onKeyPress(key)
if key.KeyCode == Enum.KeyCode.E and player.PlayerGui.ScreenGui.Frame.Visible == true then
OpenDoor()
end
end
UIS.InputBegan:connect(onKeyPress)
Create your own OpenDoor function like this:
function OpenDoor()
end
local OpenDoor = function()
end
Hope I helped! If you are confused about ANYTHING regarding GUI's, UserInputService, I will be more than happy to provide links or information.
Also PLEASE accept my answer, if it helped you, or if it was right.
5 comments
But, the GUI doens't show up, it is in starterGui
No, this isn't how GUI's work. All content in StarterGUI, are copied into the PlayerGUI. Using StarterGUI, would make every player see it.
Oh thanks!
https://scriptinghelpers.org/blog/common-mistakes#PlayerGui
Np. Remember, feel free to ask me more questions, I'm very open, and happy to help =)