Hi,
I’m making a shop GUI, and it opens with a proximity prompt. That works perfectly fine. Now, I’d like it to close when you walk away (10 studs distance). I tried using .Magnitude but that didn’t seem to work, and it didn’t yield any errors. Am I doing it wrong? Any help would be greatly appreciated.
local prox = shopkeeper.ProximityPrompt
prox.Triggered:Connect(function(player)
player.PlayerGui.ScreenGui.ShopFrame.Visible = true
player.PlayerGui.ScreenGui.Icons.Visible = false
player.CharacterAdded:Connect(function(character)
local HRP = character:WaitForChild("HumanoidRootPart")
local dist = (shopkeeper.Position - HRP.Position).Magnitude
if dist > 10 then
player.PlayerGui.ScreenGui.ShopFrame.Visible = false
player.PlayerGui.ScreenGui.Icons.Visible = true
end
end)
end)
The ProximityPrompt should have an Active property that signifies when it’s visible, and in range. You could just check for that property being false, then close the gui!
local shopkeeper = game.Workspace.Lobby.Shop.Mine.Dwasimwiz1
local prox = shopkeeper.ProximityPrompt
prox.Triggered:Connect(function(player)
if player.Name == game.Players.LocalPlayer.Name then
script.Parent.Visible = true
script.Parent.Parent.Icons.Visible = false
while wait(0.5) do
local dist = player:DistanceFromCharacter(shopkeeper.Position)
if dist > 10 then
script.Parent.Visible = false
script.Parent.Parent.Icons.Visible = true
end
end
end
end)
Sorry about that…
This will update every half second, so it should be okay.
As this is run on the client you may as well get rid of the distance check and just rely on the Proximity prompt show / hide distance.That way you won’t be showing unusable prompts to players.