How would I do this?

how would I make it so If I’m close to a part a gui pops up? and it says “E” and if you click E while over there a gui shows up, then u could hit E again for it to close.

and if ur not close to the part then the “E” gui doesnt appear

Edit: I got

local plr = game.Players.LocalPlayer

plr:GetMouse().KeyDown:Connect(function(K)
if K == "e" then
 script.Parent.Visible = true
end
end)

but I wanna make it so if you click e and ur far away then it dont work and if ur close and u hit e the gui shows, and I want a text label to show if ur close, but if ur not close make the label visible set to false.

1 Like

You should use magnitude in a local script with run service, I’d say. Might be laggy, might be a better way but, I think it would go something like this.

game:GetService("RunService").RenderStepped:Connect(function()
if (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - Part.Position).Magnitude == number then
game.GuiStoragePlaceYouUse.Gui.Parent = game.Players.LocalPlayer.PlayerGui
end
end)

It’s a bit late at night, so there might be some code errors. I’m kinda tired.

I recommend you @Alvin_Blox tutorials

I hope this will help you

Well, that doesn’t help with distance at all.

what would I put as the numbers?

The distance away you want the activation distance to be.

Personally i will set Enum.KeyCode.E and not e but it should work too

UserInputService to detect touch

Magnitude to check distance

Gah! No!

I hate how commonly UserInputService is thrown up! Use the ContextActionService! It allows for support for built in mobile buttons, for mobile support.
I only use UserInputService for detecting device type and such.

2 Likes

Main point of the message being use magnitude to check distance

Thx for the tips, i don’t know that ContextActionService adapte itself for mobile :laughing:

Where would I put the local script?

Yeah, you set the position and the image/text on the button. No custom gui stuff needed.

You would put it in PlayerScripts

1 Like

Anywhere a local script should work, I’d do PlayerScripts, because StarterGui would make the code rerun every death.

1 Like
: attempt to index nil with 'HumanoidRootPart

error

Do you use some custom character rig? Also,

For these types of things I use math to detect if a player is in the region on a loop. If you are worried about lag the loop does not have to be so frequent since it is not critical for the gui to appear exactly when the player comes in range. For your case it is a simple distance check with magnitude.

An alternative would be to create a part and use the touched event to initiate the gui. It may be buggy so to remove it maybe track distance. You might also have to add a TouchInterest to the character for it to be recognized.

1 Like

im using my own ccharacter, no custom rigs.

Hmm. Must be some sort of misspelling… Let me check… I don’t see anything…

1 Like