我需要一个脚本,该脚本可以在每个玩家触摸某个部分时更改每个玩家的声音。声音应该是特定于玩家的。我希望脚本可以在本地播放器上运行,这样每当他触摸某个部分时,声音就应该在他的机器上播放,而不是在其他播放器上播放。我有每个舞台都有独特声音的地方。就像我的地方有大约 15 种声音,所以它们应该在玩家触摸时播放
stage1 -> 为 stage1 播放声音 stage2-> 停止 stage1 的声音,为 stage2 播放声音
很快...
Make a script that puts the sound in game.Players.LocalPlayer.PlayerGui
为此,您可以采取许多不同的方法。您可以这样做的一种方法是将声音放在 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