Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i make a clickdetector execute a script?

i have finna been searching how to execute or run a script by using clickdetector but find 0 heck. anyoNE knows hwo to doE?

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)

4 comments

0

hhh its complicated could you explain it a little bit more easier to understand?

0

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.

0

http://collabedit.com/aqrhc I can show you here

0

'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.

This discussion is preserved as it was. New answers, comments, and votes are closed.