如何使每个玩家都从歌曲的开头开始播放?

脚本从列表中随机选择一首歌曲并在玩家加入时播放。这个功能完美地运行了,但当另一个用户加入时,它会将第二个玩家的歌曲与第一个玩家的同步。我正在尝试找出一个方法,使每个用户加入时,歌曲都从开头开始播放。 代码:

--Script Created by Sheasu
local songs = script.Parent
local tablee = {}
local lastsong = nil

for i,v in pairs(songs:GetChildren()) do
    if v:IsA("Sound") then
        table.insert(tablee,v)
    end
end

while true do
    for a,c in pairs(tablee) do
        local chosensong = tablee[math.random(1,#tablee)]
        repeat wait() chosensong = tablee[math.random(1,#tablee)] until chosensong ~= lastsong
        lastsong = chosensong
        chosensong:Play()
        chosensong.Ended:Wait()
        chosensong:Stop()
    end
    wait()
end

原文链接 https://stackoverflow.com/questions/70204958

点赞
stackoverflow用户19320592
stackoverflow用户19320592

你可以在本地脚本中运行它,这应该能够工作。

2022-06-11 17:36:09