Hello everyone,
I’m trying to make a shop GUI that only opens in the lobby, and I’m using ProximityPrompt and when the user presses E a GUI opens, and I would like the GUI to close when the user gets teleported to the map.
I was thinking of making something that goes like:
Create a transparent block around the lobby and maybe make a script that detects when the player is in this block and therefore the GUI remains open, but when the player leaves this block, it automatically closes. But I have no idea on how to do that, since I’m not a scripter.
You may use the distance of the player to the shop (preferably by using the same position of the ProximityPrompt).
If the player is within distance, the client’s (player’s) Shop GUI may be visible upon pressing E, but if the player is away from the shop, it must automatically close.
If you placed your Prompt instance in a Part, get the position of the character (perhaps from HumanoidRootPart), and the Part’s position. Subtract both positions, get the .Magnitude, that’s your distance.
local Distance_From_Shop = (PromptPart.Position - Player.Character.HumanoidRootPart.Position).Magnitude
To check if the player is away (including teleporting away), have a maximum distance, and compare that to the distance from shop.
local Max_Distance = 10 -- studs
game:GetService("RunService").RenderStepped:Connect(function()
local Distance_From_Shop = (PromptPart.Position - Player.Character.HumanoidRootPart.Position).Magnitude
if Distance_From_Shop < Max_Distance then
-- you may then allow the ui to appear while in range.
else
-- check if the ui is visible. if it is, hide it, and somehow disallow opening the ui.
end
end)