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.
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 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.
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.