【问题标题】:Sound script for local players in ROBLOXROBLOX 中本地玩家的声音脚本
【发布时间】:2015-05-17 11:02:40
【问题描述】:

我需要一个脚本,该脚本可以在每个玩家触摸某个部件时改变每个玩家的声音。声音应该是特定于玩家的。 我希望脚本可以在本地播放器上运行,这样每当他触摸某个部分时,声音就应该在他的机器上播放,而不是在其他播放器上播放。我有每个舞台都有独特声音的地方。就像我的地方有大约 15 种声音,所以它们应该在玩家触摸时播放

stage1 -> 为 stage1 播放声音 stage2-> 停止 stage1 的声音,为 stage2 播放声音

等等……

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    制作一个将声音放入 game.Players.LocalPlayer.PlayerGui 的脚本

    【讨论】:

    • 我试过了,但它没有按预期工作。这是我的脚本。
    • local leaderstats = game.Players.LocalPlayer:FindFirstChild("leaderstats") if leaderstats then if leaderstats:FindFirstChild("Level") then while wait(0) do local sound = game.Workspace.SoundModel :GetChildren() for x = 1, #sounds do if x == leaderstats.Level.Value then local sound =sounds[x] if not leaderstats.Parent.PlayerGui:FindFirstChild(sound) then for _,sons in pair(game .Players.LocalPlayer.PlayerGui:GetChildren())do if sons.ClassName == "Sound" then sons:Destroy() endend local clone = sound:Clone() clone.Parent = game.Players.LocalPlayer.PlayerGui clone:Play () endendendendendend
    【解决方案2】:

    为此,您可以采取许多不同的方法。一种方法是将声音放在 player.Backpack 或 player.PlayerGui 或本地播放器中的任何位置的文件夹中,然后在播放之前更改 soundid。

        local soundids = {}
        soundids[1] = 478920872
        soundids[2] = 478920872
        soundids[3] = 478920872
        soundids[4] = 478920872
        soundids[5] = 478920872
        soundids[6] = 478920872
        soundids[7] = 478920872
        soundids[8] = 478920872
        soundids[9] = 478920872
        soundids[10] = 478920872
        soundids[11] = 478920872
        soundids[12] = 478920872
        soundids[13] = 478920872
        soundids[14] = 478920872
        soundids[15] = 478920872
    
        local player = game.Players.LocalPlayer  --get localplayer
    
        local sound = player.Backpack.Sound    --get sound NOTE:the sound can be                 stored somewhere else
    
        local leaderstats = player:FindFirstChild("leaderstats")  -- get leaderstats
    
        if leaderstats and leaderstats:FindFirstChild("Level") then   -- make sure leaderstats and leaderstats.level exists
    
            local level = leaderstats.Level           
            local levelnum = level.Value   --record level.Value for comparison
    
            level.Changed:connect(function()  --if a property of level changes then run this function
                if levelnum ~= level.Value then  --make sure that the property changed was the Value property 
                    levelnum = level.Value      --record the new Value
                    if soundids[levelnum] ~= nil then  --make sure the soundid exists to avoid an error
                        sound.SoundId = 'rbxassetid://'..soundids[levelnum]  --change the Sound.SoundId to the levels' corresponding sound   
                        sound:Play() -- play the sound
                    end
                end
            end)
        end 
    

    【讨论】:

      猜你喜欢
      • 2019-06-27
      • 2021-06-16
      • 2021-10-17
      • 2021-08-23
      • 2021-11-18
      • 1970-01-01
      • 2018-12-28
      • 2020-11-21
      • 2022-10-05
      相关资源
      最近更新 更多