Why can my Gui still pop up after leaving the area?
I'm making a gui for a npc and when you get close you can press e to open it.
It works fine at first but after the first time of leaving the area you can still press e to open the gui!
I'm dealing with a local script under StarterPlayerScripts:
01 | local uis = game:GetService( "UserInputService" ) |
02 | local RegionDetector = require(script.RegionDetector) |
04 | local NpcRange = RegionDetector:NewRegion(workspace.Tim.HumanoidRootPart.Position, 20 ) |
06 | function NpcRange.EnteredRegion() |
08 | workspace.E.BillboardGui.Enabled = true |
10 | print ( "Player has entered the region" ) |
12 | uis.InputBegan:Connect( function (input, gP) if not gP then |
13 | if input.UserInputType.Name = = "Keyboard" and |
14 | input.KeyCode.Name = = "E" then |
15 | game.Players.LocalPlayer.PlayerGui.TimGui.Frame.Visible = true |
28 | function NpcRange.LeftRegion() |
29 | workspace.E.BillboardGui.Enabled = false |
30 | game.Players.LocalPlayer.PlayerGui.TimGui.Frame.Visible = false |
31 | game.Players.LocalPlayer.PlayerGui.TimGui.ScrollingFrame.Visible = false |
32 | print ( "Player has left the region" ) |
Anyways to make the UserInputService go away then come back when you step in?
I also have a module script under the local script but it just deals with the areas of the npc.