Hi
I’ve got a problem, that my script just don’t want to delete the sound after creating it. No errors in output, its silent.
-- gui transitions
function module.blackCover (duration, easing_style, easing_direction, waiting)
local sg = Instance.new("ScreenGui", player.PlayerGui) -- screen gui
sg.ScreenInsets = Enum.ScreenInsets.None
sg.SafeAreaCompatibility = Enum.SafeAreaCompatibility.None
sg.ClipToDeviceSafeArea = false
sg.DisplayOrder = 999
sg.Name = "backCover animation"
local image_label = Instance.new("ImageLabel", sg) -- image
image_label.Image = 0
image_label.AnchorPoint = Vector2.new(0.5, 0.5)
image_label.Position = UDim2.new(0.5, 0, -0.5, 0)
image_label.Size = UDim2.new(1,0,1,0)
image_label.BackgroundColor3 = Color3.fromRGB(0, 0, 0) -- gradient
local gradient = Instance.new("UIGradient", image_label)
gradient.Transparency = NumberSequence.new{
NumberSequenceKeypoint.new(0, 1),
NumberSequenceKeypoint.new(0.5, 0),
NumberSequenceKeypoint.new(1, 1)
}
gradient.Rotation = 90
-- tweens
-- fflags
local lighting_exposure_after_tween = lighting.ExposureCompensation + 5
local imageT = ts:Create(image_label, TweenInfo.new(duration, Enum.EasingStyle[easing_style], Enum.EasingDirection[easing_direction]), {Position = UDim2.new(0.5, 0, 1.5, 0)})
local lightExposureT = ts:Create(lighting, TweenInfo.new(duration / 2, Enum.EasingStyle[easing_style], Enum.EasingDirection.In), {ExposureCompensation = lighting_exposure_after_tween})
local lightExposureT_II = ts:Create(lighting, TweenInfo.new(duration / 2, Enum.EasingStyle[easing_style], Enum.EasingDirection.Out), {ExposureCompensation = lighting_exposure_after_tween - 5})
-- sound
task.spawn(function()
local sound = Instance.new("Sound", game.SoundService)
sound.Name = "wind"
sound.SoundId = "rbxassetid://105756804398751"
sound.SoundGroup = game.SoundService.Sounds
sound.Volume = 1
sound:Play()
sound.Ended:Wait()
sound:Destroy()
end)
-- playing tweens
imageT:Play(); lightExposureT:Play()
-- deleting if finished. No reason to leave it.
imageT.Completed:Once(function()
sg:Destroy()
end)
-- playing more tweens
lightExposureT.Completed:Wait()
lightExposureT_II:Play()
if waiting then
lightExposureT_II.Completed:Wait()
end
end -- function end
This is my module script. it should making transitions in the game for gui. The problem at “local sound = Instance.new(“Sound”, game.SoundService)”
it doesn’t delete the sound.
Before you will call me an idiot, I’ve used task.spawn, because its 1 of the solutions I’ve tried to fix it. I also tried using function “sound.Ended”, or “task.delay”. No, it just doesn’t delete. When I tried to use print after deletion, the print doesn’t appear, so my script just doesn’t even try to delete it, and sound stays forever in the sound service. More animations = less ram left. Bad for optimization.
Does somebody knows how to fix it? I’ll be appericate to anyone with help. Maybe is there a problem I don’t see? Please, help