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

Script I made where when a button is pressed, a sound is heard only works sometimes?

Asked by
8391ice 91
5 years ago

So I made this little button GUI that will grow and shrink a bit when clicked on, as well as make a sound. While the former works, it only makes the sound like 80 percent of the time... is there some hidden rule about sounds that I don't know about?

local debounce = false
local p = script.Parent.Parent

function anim()
    if p.Position.Y.Scale >= .75 and script.Parent.Parent.Parent.Parent.Clicked.Value == true then
        p:TweenSizeAndPosition(UDim2.new(.32, 0, .17, 0), UDim2.new(.49, 0, .74, 0), 'Out', 'Linear', .05) --Making the button slightly bigger when clicked
    end
    local sound = p.Parent.Parent.Parent.Parent.Sound.Button.Button1 --I have a template sound stored so that I can edit it as I wish
    local newSound = sound:Clone()
    newSound.Parent = script.Parent
    newSound.Volume = sound.Parent.Value * sound.Volume
    newSound:Play()
    wait(.05)
    if p.Position.Y.Scale <= .75 and script.Parent.Parent.Parent.Parent.Clicked.Value == true then
        p:TweenSizeAndPosition(UDim2.new(.3, 0, .15, 0), UDim2.new(.5, 0, .75, 0), 'Out', 'Linear', .05) --Shrinking it back down .05 sec later
    end
    repeat wait() until newSound.IsPlaying == false
    newSound:Destroy() --Destroy the sound when it's finished playing
end

script.Parent.MouseButton1Up:connect(function()
    if debounce == false then
        debounce = true
        anim() --Firing the above function
        script.Parent.Parent.Parent.Parent.Click.Value = 1
    end
    repeat wait() until script.Parent.Parent.Parent.Parent.Click.Value == 0
    debounce = false
end)
0
What's the sound.Parent.Value? SteamG00B 1633 — 5y
0
On line 11, change it to 'newSound.Volume = volumenumber' instead of all of those multiples and values. It's much easier and works the same way. And it may be the solution for your cause. TheOnlySmarts 233 — 5y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

The only thing that I can see here that may be causing your problem is the newSound.Volume = sound.Parent.Value * sound.Volume

Sometimes when the volume gets too loud some speakers won't play it because it's out of the range of what the speaker can physically play.

Also it could be that for whatever value it is being multiplied by, it is equalling to a number greater than 10 which is the max volume a sound can be.

Ad

Answer this question