Sound playing system only plays once

Hello! I made a soundid playing system in which it repeats the sounds it gets from a module script but it only plays all the sounds one round and then stops for some reason here are the scripts:

Script
local sound = game.ReplicatedStorage.Sound
local Module = require(game.ReplicatedStorage.ModuleScript)

while true do
	if script.E.Value == Module.AmoutOfMusic + 1 then
		script.E.Value = 1
	end
	print(Module[script.E.Value])
	sound.SoundId = "rbxassetid://"..Module[script.E.Value]
	sound:Play()
	sound.Ended:Wait()
	script.E.Value = script.E.Value + 1
end
Module script
return {
	["AmoutOfMusic"] = 2,
	[2] = 130791919,
	[1] = 130758889,
}

Any help for why this might happen will be very appreciated! c:

1 Like
local replicated_storage = game:GetService("ReplicatedStorage")
local Module = require(replicated_storage.ModuleScript)

local position = 1
local asset_url = "rbxassetid://"

while true do
	if (position = Module.AmoutOfMusic + 1) then
		position = 1
	end
	local sound = Instance.new("Sound", replicated_storage)
	sound.SoundId = asset_url..Module[position]
	sound:Play()
	sound.Ended:Wait()
	sound:Destroy()
	position = position + 1
end
1 Like