Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.