简体   繁体   中英

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM