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

(Solved) TextButton not detecting button.Activated?

Asked by 3 years ago
Edited 3 years ago

I have TextButtons that were made from Instance.new() that won't detect button.Activated when I save the project as a plugin. However, it will detect button.Activated when I test the project as a StarterGui. I can't seem to find the solution.

Right now, I am testing this code in a LocalScript that won't work.

local button = script.Parent
button.Activated:Connect(function()
     print("Test successful!")
end)

And yes, the project is in CoreGui. This is where I am testing from.

2 answers

Log in to vote
0
Answered by 3 years ago

use MouseButton1Down (or MouseButton1Up or MouseButton1Click) instead of button.Activated.

local button = script.Parent
button.MouseButton1Down:Connect(function()
    print("Test successful, MouseButton1Down")
end)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I found the answer. This took a while.

First of all, the problem, the real one. I was searching and trying to pinpoint the problem. The script wasn't responding to button.Activated because the script was cloned. It didn't have a chance to run so it couldn't prepare to respond to button.Activated.

Secondly, the answer. I used a ModuleScript. At first I thought that ModuleScripts don't respond to Connect(), but I tested it out and found out that ModuleScripts do respond to Connect(). This solution works because of the fact that you can run ModuleScripts from other scripts. You don't need to do anything with the returned value. The command to run a ModuleScript is down below.

local returnedValue = require(clone) -- Replace 'clone' with the Instance of the cloned ModuleScript.

Lastly, the credits. The person who said to use ModuleScripts is MeaxisDev on DevForum who got the information from @qothiu on Discord. Thanks to both of you!

Answer this question