I'm making an ATM machine for a roleplay game I'm working on. I made an "E to interact" and it worked with print so I replaced it with making the ATM Gui visible. It didn't work and there wasn't errors. I tried debugging and it came out positive. My code is a LocalScript:
01 | local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild( "HumanoidRootPart" ) |
02 | local UIS = game:GetService( "UserInputService" ) |
03 | local Atm = game.Workspace.Atm |
04 |
05 | UIS.InputBegan:Connect( function (keyCode) |
06 | if keyCode.keyCode = = Enum.KeyCode.E then |
07 | if (Atm.Position - HumanoidRootPart.Position).magnitude < 10 then |
08 | game.StarterGui.ScreenGui.FinnianATM.Visible = true |
09 | print ( "Worked" ) |
10 | end |
11 | end |
12 | end ) |
Instead of using "Visible = True", I normally Use "Enabled = True" or Enabled = False".
1 | if keyCode.keyCode = = Enum.KeyCode.E then |
to
1 | if keyCode.keyCode = = Enum.KeyCode.e then |
probably
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local ATMHitBox = game:GetService( "Workspace" ):FindFirstChild( "ATM" ).HitBox |
03 | local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() |
04 |
05 | wait( 0.25 ) --Wait For The Character To FULLY Load In |
06 |
07 | local HRP = Character:FindFirstChild( "HumanoidRootPart" ) |
08 |
09 | UIS.InputBegan:Connect( function (key) |
10 | if key.KeyCode = = Enum.KeyCode.E then |
11 | if (ATMHitBox.Position - HRP.Position).Magnitude < 10 then |
12 | --Whatever You Want To Happen |
13 | print ( "Works" ) |
14 | end |
15 | end |
16 | end ) |
This Also Works As Well