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

How to make a parts size change when sound is loud?

Asked by 5 years ago

Dont know any of the code for this, please help.

1
Do you mean change the size of the part when the volume increases? Or do you mean when the player gets closer to the source of the sound? martingalethreat 81 — 5y
0
When the volume increases User#29913 36 — 5y

1 answer

Log in to vote
0
Answered by
0b1w 13
5 years ago
Edited 5 years ago

Here you go, I hope this helps!

wait();

local TweenService = game:GetService("TweenService");

local soundId = 00000000;

local tweenInfo = TweenInfo.new(
    0.06,
    Enum.EasingStyle.Quad
);

local Part = Instance.new("Part");
Part.BrickColor = BrickColor.Red();
Part.Size = Vector3.new(10,10,10);
Part.Position = Vector3.new(0,20,0);
Part.Anchored = true;
Part.TopSurface = Enum.SurfaceType.Smooth;
Part.BottomSurface = Enum.SurfaceType.Smooth;
Part.Parent = workspace;

local Sound = Instance.new("Sound");
Sound.SoundId = soundId
Sound.Volume = 1;
Sound.Parent = Part;

local lastTween = nil;

repeat wait(); until (Sound.IsLoaded);

Sound:Play();

local function loudnessChanged()
    local Loudness = Sound.PlaybackLoudness;
    local Math = (10*Loudness/5)
    local Vec = Vector3.new(Math,Math,Math);
    local Tween = TweenService:Create(Part,tweenInfo,{Size = Vec}):Play();
    if (lastTween) then
        lastTween:Destroy();
    end;
    lastTween = Tween;
end;

Sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(loudnessChanged);
0
not quite... but KEEP SCRIPTING!! User#29913 36 — 5y
Ad

Answer this question