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

How to crop a sound?

Asked by 9 years ago

So I made this script:

function onPlayerAdded()
    local RandNum = Instance.new("NumberValue")
    RandNum.Value = math.random(10)
    for i,v in pairs(game.Players:GetChildren()) do
        if v:IsA("Player") then
            RandNum.Parent = v
            RandNum.Name = "RandomNumber"
                if RandNum.Value <= 3 then
                    game.Workspace.Sounds.Firework:Play()
                    local LuckMessage = Instance.new("Message", game.Workspace)
                        LuckMessage.Text = RandNum.Parent.Name .. " got lucky! Good job!"
                        wait(5)
                        LuckMessage:Destroy()
                elseif RandNum.Value >= 8 then
                    local UnLuckMessage = Instance.new("Message", game.Workspace)
                        game.Workspace.Sounds.Suspense:Play()
                        UnLuckMessage.Text = RandNum.Parent.Name .. " got unlucky. Sorry."
                        wait(5)
                        UnLuckMessage:Destroy()
                            local UnLuckExplode = Instance.new("Explosion")
                                for i,v in pairs(game.Workspace:GetChildren()) do
                                    if v:IsA("Model") then
                                        UnLuckExplode.Parent = v.Torso
                                end
                        end
                end
        end
    end
end

game.Players.PlayerAdded:connect(onPlayerAdded)

for _,v in pairs(game.Players:GetChildren()) do
    if v:IsA("Player") then
        onPlayerAdded()
    end
end

And the Firework sound effect just goes on too long. If I try to put a wait(18) there, then it will delay the message. Can someone help me? Thanks! :)

2 answers

Log in to vote
0
Answered by
Reselim 35
9 years ago

You'd put:

delay(18, function()
    sound:Stop()
end)

Basically, what that does is wait a number of time, then call the function.

Hope this helps! :)

Ad
Log in to vote
0
Answered by
lomo0987 250 Moderation Voter
9 years ago

http://wiki.roblox.com/index.php?title=API:Class/Sound/Stop

all you need to do is to ":Stop()" the music. :D

0
I know HOW, but I want to know how to do it without it delaying the message. RadiantSolarium 35 — 9y
0
I'm sure that wouldnt Delay it.. SamTheDeveloper 85 — 9y
0
Well, it did. RadiantSolarium 35 — 9y

Answer this question