Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could I go about making a GUI close when you walk away?

I have a click detector to open it and a text button to close it but I want it to close when you walk a certain distance away so people can't keep the GUI open for using it to their advantage.

3 comments

1

Keep checking the distance between the click detector part and the player's torso (minus their positions and then Vector3.Magnitude) if the distance is greater than let's say 20 studs then find the Gui in the player and destroy it.

0

Could you post your script, so we can see where you went wrong and it's easier for us to help you?

0

Use magnitude.

2 answers

✓ Accepted answer

Find the Part that makes the gui open and find the player's HumanoidRootPart.

Next Find RunService using

local RunService = game:GetService("RunService")

Now run this function which uses magnitude to find the distance between the player and the part.

RunService.RenderStepped:Connect(function()
	if (GuiPart.Position - HumanoidRootPart.Position).Magnitude < 15 then
		Gui.Visible = true
	else
		Gui.Visible = false
	end
end)

Feel free to change the 15 to something lower or higher.

1 comment

0

RenderStepped is Client-Sided, so you might want to change it to RunServer.Stepped:Connect(function().

When a player steps on a part the GUI comes When a player steps on another GUI when it leaves

This discussion is preserved as it was. New answers, comments, and votes are closed.