ROBLOX中本地玩家的声音脚本

时间:2015-03-15 06:55:12

标签: lua roblox

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

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

等......

2 个答案:

答案 0 :(得分:0)

制作一个将声音置于游戏中的脚本.Players.LocalPlayer.PlayerGui

答案 1 :(得分:0)

您可以采取许多不同的方法。你可以做到的一种方法是将声音放在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