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.
local r = math.random(0,255) local g = r local b = g game.StarterGui.ScreenGui.TextButton.ClickDetector.MouseClick:Connect(function() game.Workspace.Part.Color = Color3.fromRGB(r, g, b) 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.
local player = game:GetService("Players").LocalPlayer local playerGui = player:WaitForChild("PlayerGui") script.Parent.MouseButton1Click:Connect(function() -- This is it. -- Do your code here. end)