Hello I am trying to make a speakers bass move to the beat of an audio. However, im not quite sure if I am going about this situation correctly. Basically all I want to do is detect if there is audio playing and then make my part move based on the audios bass or whatever.
When doing it the way I have, it will constantly keep firing and it does not seem like it is working correctly. Can someone help me out???
while active_LOOPS[newVal] ~= nil and Currval == true do --INFINITE LOOP. only while the script can find the corresponding value in the active table
task.wait(math.random() * 0.6)
local SPEAKERS = vars.Parts["Speakers"];
local AUDIO = vars.Parts["Audio"];
if AUDIO.IsPlaying == true and AUDIO.PlaybackLoudness > 50 then
for _,obj in pairs(SPEAKERS:GetDescendants()) do
if obj.ClassName == "Model" then
if obj:FindFirstChild("FX") then
local bumper = obj.BassBumper
local FX = obj.FX
local goal = {}
--bump:
if vars._POWER_SWITCH_.Value == true then
goal.Size = Vector3.new(bumper.Size.X, bumper.Size.Y, bumper.Size.Z)
bumper.Size = Vector3.new(bumper.Size.X,AUDIO.PlaybackLoudness*0.001,bumper.Size.Z) --Make the bass bumper move
task.wait()
local tween = tweenService:Create(bumper, TweenInfo.new(0.175), goal) --smooth move back to original position
tween:Play()
FX.Value = true
task.wait(math.random() * 0.2)
end
end
end
end
end
end
This is what I have. Do you think it is good? It is not final product. I just threw something together. I am trying to make the part resize to the majority of the beat of every song. I am not sure I like the randomness? I am trying to go for more audio related that time related if that makes sense.
while true do --INFINITE LOOP. only while the script can find the corresponding value in the active table
task.wait(0.2 + math.random() * 0.4)
local SPEAKERS = vars.Parts["Speakers"];
local AUDIO = vars.Parts["Audio"];
local boolValue = Instance.new("BoolValue")
local randomNumber = math.random() * AUDIO.PlaybackLoudness * 0.01
local randomBool = randomNumber > 0.4 --??
boolValue.Value = randomBool
if boolValue.Value == true then
local choice = true
for i = 1, math.random(1,5) do
choice = not choice
end
local bumper = obj.BassBumper
local FX = obj.FX
local goal = {}
goal.Size = Vector3.new(bumper.Size.X, bumper.Size.Y, bumper.Size.Z)
bumper.Size = Vector3.new(bumper.Size.X,AUDIO.PlaybackLoudness*0.001,bumper.Size.Z) --Make the bass bumper move
task.wait()
local tween = tweenService:Create(bumper, TweenInfo.new(0.175), goal) --smooth move back to original position
tween:Play()
if choice == false then
--other code
end
end
end
while active_LOOPS[newVal] ~= nil do --INFINITE LOOP. only while the script can find the corresponding value in the active table
task.wait(0.2 + math.random() * 0.4)
--task.wait(0.3)
--task.wait(0.03)
local SPEAKERS = vars.Parts["Speakers"];
local AUDIO = vars.Parts["Audio"];
if AUDIO.IsPlaying == true and vars._POWER_SWITCH_.Value == true and AUDIO.TimeLength >0 then
local boolValue = Instance.new("BoolValue")
local randomNumber = math.random() * AUDIO.PlaybackLoudness * 0.01 -- Generate a random number based on the playback loudness
-- Convert the random number to a boolean:
local randomBool = randomNumber > 0.7 -- Adjust someThreshold based on your preference
print(randomNumber) --for testing purposes.
-- Set the BoolValue
boolValue.Value = randomBool
print(boolValue.Value) --for testing purposes
if randomNumber > 0.5 then
for _,obj in pairs(SPEAKERS:GetDescendants()) do
if obj.ClassName == "Model" then
if obj:FindFirstChild("FX") then
local bumper = obj.BassBumper
local FX = obj.FX
local goal = {}
goal.Size = Vector3.new(bumper.Size.X, bumper.Size.Y, bumper.Size.Z)
bumper.Size = Vector3.new(bumper.Size.X,AUDIO.PlaybackLoudness*0.001,bumper.Size.Z) --Make the bass bumper move
task.wait()
local tween = tweenService:Create(bumper, TweenInfo.new(0.175), goal) --smooth move back to original position
tween:Play()
end
end
end
end
--Play FX:
if boolValue.Value == true then
for _,obj in pairs(SPEAKERS:GetDescendants()) do
if obj.ClassName == "Model" then
if obj:FindFirstChild("FX") then
local FX = obj.FX
if FX.Value == false then
FX.Value = true
end
task.wait(math.random() * 0.02)
end
end
end
end
end
end
Im trying to make my part move to the beat but it is just random. If I dont use a wait, it just beats to everything