Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pressing E not making Gui visible but no errors?

Asked by
8jxms 9
4 years ago

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:

local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Atm = game.Workspace.Atm

UIS.InputBegan:Connect(function(keyCode)
    if keyCode.keyCode == Enum.KeyCode.E then
        if (Atm.Position - HumanoidRootPart.Position).magnitude <10 then
            game.StarterGui.ScreenGui.FinnianATM.Visible = true
            print("Worked")
        end
    end
end)
0
The error that I assume is on line 7, where it talks about the ATM. You can't get the ATM position, you can only get the position of one part inside of the ATM, considering if it's a model or not. If it is a model, make a HitBox part that is the size of the ATM and make it transparent, and no Collidable and then use that position for the magnitude. killerbrenden 1537 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

Instead of using "Visible = True", I normally Use "Enabled = True" or Enabled = False".

0
Could you explain how I would go about using that? (I've never used enabled before) 8jxms 9 — 4y
0
Enabled is a ScreenGUI property where you can have all the components of the GUI Enabled or Disabled. killerbrenden 1537 — 4y
0
Enabled Just means that the "Gui" is allowed to be Used or Not. and it also sets the Visibility respectively. ffancyaxax12 181 — 4y
0
It still didn't work again, no errors 8jxms 9 — 4y
View all comments (5 more)
0
where did you put your local script? ffancyaxax12 181 — 4y
0
oh wait omg im so dumb i put it in startergui lol I can just do script.parent.screengui lemme try it 8jxms 9 — 4y
0
Can someone help me? WN0820 11 — 4y
0
I'll still post your answer as worked thanks for the help 8jxms 9 — 4y
0
Np :) ffancyaxax12 181 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
if keyCode.keyCode == Enum.KeyCode.E then

to

if keyCode.keyCode == Enum.KeyCode.e then

probably

0
No it isn't that because it's working with print 8jxms 9 — 4y
Log in to vote
0
Answered by 4 years ago
local UIS = game:GetService("UserInputService")
local ATMHitBox = game:GetService("Workspace"):FindFirstChild("ATM").HitBox
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

wait(0.25) --Wait For The Character To FULLY Load In

local HRP = Character:FindFirstChild("HumanoidRootPart")

UIS.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.E then
        if (ATMHitBox.Position - HRP.Position).Magnitude < 10 then
            --Whatever You Want To Happen
            print("Works")
        end
    end
end)

This Also Works As Well

Answer this question