Search code examples
luaroblox

Click detector event is not functioning


I have made this code; what I want is so when the part is clicked, it does the function fadeWaitShow, but it does not seem to be working. I tried putting it in a loop but it would just do the function again and again by itself. Help, if you can and thanks! (Code is below)


local click = script.Parent.ClickDetector

local function fade()
   script.Parent.CanCollide = false
   script.Parent.Transparency = 0.5
end

local function show()
   script.Parent.CanCollide = true
   script.Parent.Transparency = 0
end

local function fadeWaitShow ()
   fade()
   wait(1)
   show()
end

   click.MouseClick:Connect(fadeWaitShow())
   

Thanks!

Solution

  • In your MouseClick connection, you are calling the function instead of passing the function handle to the connection. This results in the code evaluating the line as click.MouseClick:Connect().

    So to fix this, don't call the function.

    click.MouseClick:Connect(fadeWaitShow)