Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i make a clickdetector execute a script?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by 5 years ago
local ClickDetector = script.Parent

ClickDetector.MouseClick:Connect(function()
    -- code
end)

runs on click

Ad
Log in to vote
0
Answered by 5 years ago

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)
0
hhh its complicated could you explain it a little bit more easier to understand? REXstronk 0 — 5y
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. Sergiomontani10 236 — 5y
0
http://collabedit.com/aqrhc I can show you here Sergiomontani10 236 — 5y
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. cringe_worthey 97 — 5y

Answer this question