My code doesn't work and I can't figure out why

Hello!

I’m trying to code a script where if the part is transparent it’ll play a sound.
The only issue is that I’m not good at coding thus my code doesn’t work, I know that this is an issue on my end but I can’t figure out what the issue is. Am I missing some crucial code?

code

1 Like

Is that a normal script, or a local script?

Yes, It is indeed a normal script.

“Am I missing some crucial code?”
You’re because sounds can only be played locally, and that I would recommend using SoundService.

Check when the parts transparency has been changed then use an if statement to see if the parts transparency is equal to 1, then play the sound from sound group…

1 Like

The problem is that you’re only checking if the part’s Transparency is 1 when the script initially runs. The script will check the value one time and never again.

You need to check via a signal or a loop if the part’s transparency changes:

script.Parent:GetPropertyChangedSignal("Transparency"):Connect(function()
    --... 
end)

You can play sounds from the server.

2 Likes

Yup, like I just described.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.