Answered by
5 years ago Edited 5 years ago
You should use WaitForChild in LocalScripts when referencing Instances (in case they didn't load yet when you're trying to use them):
1 | local sound = workspace:WaitForChild( "Sound" ) |
Because the script only runs on startup, the Sound probably won't be playing, that's because you have to listen for when it starts playing, with the Changed event:
01 | local sound = workspace:WaitForChild( "Sound" ) |
02 | local Fire = script.Parent:WaitForChild( "Fire" ) |
04 | sound:GetPropertyChangedSignal( "IsPlaying" ):Connect( function () |
06 | if sound.IsPlaying then |
07 | local PlaybackLoudness = sound.PlaybackLoudness |
09 | Fire.Size = 0.5 - (PlaybackLoudness / 1000 ) |
By the way, the reason I'm using GetPropertyChangedSignal("IsPlaying") is because it's just a shorter replacement for
1 | sound.Changed:Connect( function (PropertyName) |
2 | if PropertyName = = "IsPlaying" then |
But, a simpler way of doing this is checking when the PlaybackLoudness itself changes, like this:
1 | local sound = workspace:WaitForChild( "Sound" ) |
2 | local Fire = script.Parent:WaitForChild( "Fire" ) |
4 | sound:GetPropertyChangedSignal( "PlaybackLoudness" ):Connect( function () |
5 | local PlaybackLoudness = sound.PlaybackLoudness |
7 | Fire.Size = 0.5 - (PlaybackLoudness / 1000 ) |
Then, your particle's Size changes each time the PlaybackLoudness gets changed, without any inefficient loops