I want to play a sound as a tween is going on. This is for a crate opening thing, and I’m using tweenservice to tween the spinning effect. I want to have a sound play at the same time, and slow down as it gets closer to the centre.
-- Create tween
local Spin = TweenService:Create(
Scroll,
TweenInfo.new(
math.random(8, 10),
Enum.EasingStyle.Quart
),
{CanvasPosition = Vector2.new(LandingPosition, 0)}
)
Spin:Play()
Spin.Completed:Wait() -- Wait for it to be completed
Please DON’T link me to this tutorial Creating a Crate/Spin System I’ve already checked it out, and used parts of it, but I can’t get their sound system to work with mine, due to differences in the way my crate opening is setup.
Can’t seem to get it to go same pace as spin tween. As the spin reaches the end, the click sound is still going really fast. If I set the PlaybackSpeed to anything below 1 it almost drops in pitch
SpinClick:Play() -- Play the Clicking sound
coroutine.wrap(function()
local ClickSound = TweenService:Create(
SpinClick,
TweenInfo.new(
RandomTime,
Enum.EasingStyle.Quart
),
{PlaybackSpeed = 1}
)
ClickSound:Play()
ClickSound.Completed:Wait()
SpinClick:Stop()
SpinClick.PlaybackSpeed = 5
end)()
-- Create tween
local Spin = TweenService:Create(
Scroll,
TweenInfo.new(
RandomTime,
Enum.EasingStyle.Quart
),
{CanvasPosition = Vector2.new(LandingPosition, 0)}
)
Spin:Play()
Spin.Completed:Wait() -- Wait for it to be completed
sorry it been like 3 years but there might be some people who can need it. I have seen a lot of elemental games without implementing this (???).
local lastPlayedElement = 0
runService:BindToRenderStep("SpinSound",100,function()
--dividing current canvas position with frame size gives you the current element thats at the starting point of your scrolling frame,
--but we want it to calculate middle of the scrolling frame. Thats why we add the absolute size * .5
--If you use padding, I think you should add that to the calculation of the current element aswell.
local currentElement = math.ceil((spinnerFrame.ScrollingFrame.CanvasPosition.X + spinnerFrame.ScrollingFrame.AbsoluteSize.X * .5) / frameSize.X)
if LastPlayedElement ~= currentElement then
LastPlayedElement = currentElement
--use your own sound and properties
local sound: Sound = player.PlayerGui.SFX.spinsound
sound:Play()
end
end)
bind it when you start tween, unbind it when your tween ends. Frame size is the size of the frame that you put into scrolling frame.