In a previous thread we solved an issued getting sounds to play locally. It works fine in most cases but not this one. I put this script in starter player scripts, if the function doesnt meet the level requirement it should play the sounds. Nogold is s place holder sound in this script.
The problem is, this script plays the sound globally when I am calling for it to play locally. Anyone know why?
local player = game.Players.LocalPlayer
local pad = game.Workspace.factionmodels["Male Orc Morph2"].Pad
local requiredlevel = 5
local debounce = false
local SoundService = game:GetService("SoundService")
pad.Touched:Connect(function(obj)
local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
local playerLevel = plr.leaderstats.Level.Value
local function playLocalSound(soundId)
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://11222407921"
SoundService:PlayLocalSound(sound)
end
if not debounce then
debounce = true
if playerLevel < requiredlevel then
playLocalSound()
end
task.wait(2)
debounce = false
end
end)
Instead of using SoundService it tries to play the audio without it, I think using that service will make it run on the whole server even if you request it on the client.
Attempt putting the sound into the script (Parent it to the script)
This at least works in StarterGui, im not sure if it will work in StarterPlayerScripts
local player = game.Players.LocalPlayer
local pad = game.Workspace.factionmodels["Male Orc Morph2"].Pad
local requiredlevel = 5
local debounce = false
local SoundService = game:GetService("SoundService")
pad.Touched:Connect(function(obj)
local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
if plr ~= Player then
return
end
local playerLevel = plr.leaderstats.Level.Value
local function playLocalSound(soundId)
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://11222407921"
SoundService:PlayLocalSound(sound)
end
if not debounce then
debounce = true
if playerLevel < requiredlevel then
playLocalSound()
end
task.wait(2)
debounce = false
end
end)
I put a local script in starter gui. I put the sound in the script. The sound does play locally, but it does really strange things. If someone else steps on the part it plays the sound for me, but they cant hear it. It also breaks the original morph script. And it wont debounce.
local pad = game.Workspace.factionmodels["Male Orc Morph2"].Pad
local sound = script.nolevel
local player = game.Players.LocalPlayer
local debounce = false
pad.Touched:Connect(function(obj)
local playerLevel = player.leaderstats.Level.Value
local requiredLevel = 5
if not debounce then
debounce = true
if playerLevel < requiredLevel then
sound:Play()
end
task.wait()
debounce = false
end
end)
local pad = game.Workspace.factionmodels["Male Orc Morph2"].Pad
local requiredlevel = 5
local debounce = false
local SoundService = game:GetService("SoundService")
pad.Touched:Connect(function(obj)
local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
local playerLevel = plr.leaderstats.Level.Value
local function playLocalSound(soundId)
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://11222407921"
SoundService:PlayLocalSound(sound)
end
if not debounce and plr == player then
debounce = true
if playerLevel < requiredlevel then
playLocalSound()
end
task.wait(2)
debounce = false
end
end)```