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

How can I get this transparency and sound script to work?

Asked by 7 years ago

How can I get this sound to play? I want to have a script where when a mesh part becomes transparent, a sound plays.

if script.Parent.Transparency = 0 then
    script.sound:play()
end

What am I doing wrong here? It doesn't want me to do Transparency = 0.

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

The problem is, you're checking for when the script's transparency equals 0. This won't work because transparency is not a property of a script. To fix this, make a variable that searches for the part, and once found, check for when the transparency of the part is 0. When this is true, it will play the desired sound.

local part = workspace:WaitForChild(" ") --inside the quotation marks, put the parts name

while true do
    if part.Transparency == 0 then --put two equal signs indicating that it is equal to
        script.Parent.sound:Play() --do script.Parent.sound, because script.Parent is what the script is inside of, as well as Play(), because lua is case sensitive    
wait(1) --every one second, it loops this if statement
    end
end
Ad

Answer this question