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

GuiObject events are not firing inside my LocalScript?

Asked by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Hi again,

I've been stumped on this for quite a while but now that I found scriptinghelpers I really hope you guys could help me out on this :)

Basically, I am trying to get input from when the user interacts with a BillboardGui object. (more specifically the frames inside of the gui). My issue seems to be that the GuiObject events aren't triggering at all.

According to the wiki, every GuiObject instance has an event "InputBegan", which is fired when the user interacts with the GuiObject using a mouse, touch, keyboard, etc. My goal is for the ui element to be able to read user keyboard inputs, but it seems that no matter what input I do the event doesn't fire.

I've set up a LocalScript as shown in this image, and tested to make sure that the script is running by executing a print statement, and it did in fact run.

I've set up a couple of event connections to see if maybe it was just the InputBegan event, but it's replicated for every event.

Here is my local script code:

local frame = script.Parent

print("Hello from " .. frame.Name .. "! The LocalScript is running!")
-- printed successfully


frame.InputBegan:Connect(function(input)
    print("input began! " .. tostring(input))
end) -- no response


frame.MouseMoved:Connect(function(x, y)
    print("mouse moved, x: " .. x .. " y: " .. y)
end) -- no response

I've also tried setting up a LocalScript inside StarterPlayerScripts, then actively search for the ui element and run the exact same code, but I am left with identical results.

In addition to this, I've tried setting up a Script object inside with identical content, but I net the same result as I did previously.

I understand that ContextActionService can allow me to use the InputBegan event as well, but it would really be a huge help if I were able to receive inputs only when the user interacts with the gui.

I can't seem to identify the problem here, I hope you guys can help me out on this! :)

0
In line 3, you tried to concatenate an object. Instead do .. frame.Name .. Same on line 8. Make .. input .. to ..tostring(input).. and on lines 7 and 12, you used :connect when it’s :Connect. Don’t use deprecated code as ROBLOX has plans to remove it. User#19524 175 — 6y
0
Deprecated code doesn't necessarily mean that it's going to be removed, it just means that it can be removed and they don't recommend using it.  I agree that people should be using :Connect, there's a small chance that Roblox is going to remove :connect, however. Thundermaker300 554 — 6y
0
Oof. I didn't know that there was a new Connect, I just recently came back to ROBLOX. Thanks for that. The frame.Name and input stuff is unnecessary and was only to show that the script was running but I appreciate the catches. chomboghai 2044 — 6y
0
Just because code is deprecated does not mean Roblox has plans to remove it. There is almost no chance roblox will remove :connect() due to the amount of older scripts that would break. But Roblox recommends not using deprecated code for a reason. oreoollie 649 — 6y

1 answer

Log in to vote
0
Answered by
oreoollie 649 Moderation Voter
6 years ago
Edited 6 years ago

I think your problem is the Active property of GUI objects. According to the hint shown when hovering the property, "If true, this GUI object will fire mouse events and pass them to any GUI objects underneath..." This property is false by default. Try setting it to true on your GUI objects. Then test again.

I hoped my answer was useful. If it solved your problem, please remember to mark it as correct!

0
Thanks. This allows mouse inputs with GuiObjects but what I'm trying to get access to is keyboard inputs. The API reference stated that InputBegan fires when keyboard inputs are made too. chomboghai 2044 — 6y
0
I know that billboard guis are trash at input, I'm not sure if that could be causing your issue. Thundermaker300 554 — 6y
Ad

Answer this question