Sound script not working properly

Im making a tornado system, and when a part gets sucked in by it then it makes a “destroy” sound. But these sound are of course different, e.g for glass there’s glass breaking sound. The problem is, that even if it’s not a glass part, it everytime makes a glass destroying sound. Here’s the script:

local sound = script.BreakSound
local glassound1 = script.GlassSound

if not script.Parent.Parent.Parent:FindFirstChild("Humanoid") then
	if script.Parent.Parent.Material ~= Enum.Material.Glass then
		if not script.Parent.Parent:FindFirstChildWhichIsA("BreakSound") then
			local sound1 = sound:Clone()
			sound1.Parent = script.Parent.Parent
			sound1:Play()
			sound1:Destroy() -- Play on remove is turned on
			script:Destroy()
		end
	else
		if not script.Parent.Parent:FindFirstChildWhichIsA("GlassSound") then
			local glasssound = glassound1:Clone()
			glasssound.Parent = script.Parent.Parent
			glasssound:Play()
			glasssound:Destroy() -- Play on remove is turned on
			script:Destroy()
		end
	end
else
	script:Destroy()
end
1 Like

I believe it’s because you’re using ‘FindFirstChildWhichIsA’ rather than the one you want to be using, ‘FindFirstChild’. Using FindFirstChildWhichIsA(string type) is a way to find a child of an object based on the TYPE of object it is, not the name of it.

Try this:

local sound = script.BreakSound
local glassound1 = script.GlassSound

if not script.Parent.Parent.Parent:FindFirstChild("Humanoid") then
	if script.Parent.Parent.Material ~= Enum.Material.Glass then
		if not script.Parent.Parent:FindFirstChild("BreakSound") then
			local sound1 = sound:Clone()
			sound1.Parent = script.Parent.Parent
			sound1:Play()
			sound1:Destroy() -- Play on remove is turned on
			script:Destroy()
		end
	else
		if not script.Parent.Parent:FindFirstChild("GlassSound") then
			local glasssound = glassound1:Clone()
			glasssound.Parent = script.Parent.Parent
			glasssound:Play()
			glasssound:Destroy() -- Play on remove is turned on
			script:Destroy()
		end
	end
else
	script:Destroy()
end
1 Like

Oh, that was a really silly mistake, but it works now!

Also, I have another problem with my tornado. It basically just vanishes after unanchoring it. I tried changing the name(I thought maybe something was deleting it), but it still didn’t work.

I think it’ll be falling through the world if it’s can collide is false. It also depends how you’re moving the tornadoes too. I don’t see anything wrong with keeping them anchored and letting a loop, like a .Stepped event moving them.

1 Like

I’m moving them using AlignPosition. And I think they are not falling because I would see the movement.

Where’s the code that you unanchor them at?

1 Like

I don’t use code to unanchor them, they are just unanchored from the beggining.

Ahhh okay, so for the AlignPosition object, is it connected to an attachment that’s within an anchored part? You’ll want that anchored part to always be anchored.

1 Like

Align Position is set to One attachment mode, and when the storm begins, the script inside it enables and starts aligning random position within the cloud.

I found out what was causing the bug. It was the old body gyro which was inside the tornado. Thanks for help!

1 Like

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