I’m very new to developing
function onclick ()
script.parent.SurfaceGui.TextBox.Text = "Hello World!"
end
script.Parent.ClickDetector:onclick()
I’m very new to developing
function onclick ()
script.parent.SurfaceGui.TextBox.Text = "Hello World!"
end
script.Parent.ClickDetector:onclick()
In order to detect when someone activates a ClickDetector
, you need to utilize an event so that the script will be listening for that action. In this case, you can use the MouseClick
event of the ClickDetector
and :Connect
it to a designated function when it is activated.
Example #1
local ClickDetector = script.Parent.ClickDetector
local function onClick()
-- Code
end
ClickDetector.MouseClick:Connect(onClick) -- When the ClickDetector is activated, it'll be connected to the function called "onClick"
Example #2 (Anonymous Function)
local ClickDetector = script.Parent.ClickDetector
ClickDetector.MouseClick:Connect(function()
-- Code
end)
More information about ClickDetectors, events, and more, can be found from the following pages: