Ok so I have a Screen Gui which has a TextButton, and a ClickDetector inside the textbutton. Inside the TextButton is a Script. A regular one. Nothing happens.
1 | local r = math.random( 0 , 255 ) |
2 | local g = r |
3 | local b = g |
4 | game.StarterGui.ScreenGui.TextButton.ClickDetector.MouseClick:Connect( function () |
5 | game.Workspace.Part.Color = Color 3. fromRGB(r, g, b) |
6 | end ) |
Click detectors only work when parented to parts, and the script must be a LocalScript, and textbuttons have their own Mouse Click event, here it is. Also, you need to get the player's PlayerGui to access this button, as the StarterGui is just a placeholder for the gui.
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local playerGui = player:WaitForChild( "PlayerGui" ) |
3 |
4 | script.Parent.MouseButton 1 Click:Connect( function () -- This is it. |
5 | -- Do your code here. |
6 | end ) |