i have finna been searching how to execute or run a script by using clickdetector but find 0 heck. anyoNE knows hwo to doE?
COMMUNITY QUESTION
how do i make a clickdetector execute a script?
2 answers
local ClickDetector = script.Parent
ClickDetector.MouseClick:Connect(function()
-- code
end)
runs on click
You can create a function for your code to be executed when the player clicked the detector. Then let the script listen for the MouseClick property of the clickdetector, and let it fire the function.
This is how your code would be like:
local detector = script.Parent
function disIsSupposedtobefired(player)
print(player.Name.. ' has clicked the detector')
end
--you can fire the function like this
detector.MouseClick:Connect(disIsSupposedtobefired)
-- OR
detector.MouseClick:Connect(function(player)
disIsSupposedtobefired(player)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
hhh its complicated could you explain it a little bit more easier to understand?
Not a good practice to have the function firing the other function like that. You should do the same only replace the part where he fires the function with the actual code.
http://collabedit.com/aqrhc I can show you here
'Not a good practice to have the function firing the other function like that.' There's nothing wrong with making an non-anonymous function, there's no difference.