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

Sound.Paused, Sound.Ended, or Sound.Stopped not working??

Asked by 4 years ago
Edited 4 years ago
local sounds = {"158485547", "157026036", "158526174"} -- replace with your id's
local r = Random.new()
local sound = workspace:WaitForChild("Music").Sound

function pickRandomSound()
    local randomIndex = r:NextInteger(1, #sounds)
    local sound = sound.SoundId == "rbxassetid://"..sounds[randomIndex]
end

while wait(1) do
    pickRandomSound()
    print(sound.SoundId)
    sound:Play()
    sound.Stopped:Wait()
    pickRandomSound()
    print(sound.SoundId)
    sound:Play()
    sound.Stopped:Wait()
end

Here is the script so far. It's not getting Sound.Stopped. I tried all three methods and none of them worked.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The issue is with line 7

local sound = sound.SoundId == "rbxassetid://"..sounds[randomIndex]

This is not chaning the sound id. You care comparing the current sound id with the new one created and storing the result in the local variable sound. The there is also no need to have a local variable sound in the function. Lastly you should be using a local function.

local function pickRandomSound()
    local randomIndex = r:NextInteger(1, #sounds)
    sound.SoundId = "rbxassetid://"..sounds[randomIndex] -- assign the new sound id
end

In youw while loop you duplicate the logic which is not needed.

while wait(1) do
    pickRandomSound()
    print(sound.SoundId)
    sound:Play()
    sound.Stopped:Wait()
end

I hope this helps. Please comment if you have any other questions about this code.

Ad

Answer this question