Here’s the error I get in the output: SoundService:PlayLocalSound only works on a client. Does anyone know a solution to this?
Script located in ServerScriptService:
local SoundService = game:GetService("SoundService")
function onTouch(part)
part.Parent:MoveTo(game.Workspace.ToS2.Position)
wait(0.5)
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://143562367"
SoundService:PlayLocalSound(sound)
end
game.Workspace.Portals.Portal1.ToS1.Touched:Connect(onTouch)
The only way you can have any sound played locally is to have the physical sound be played on the client, no question about it. I think you would be better off to just use :Play() on the sound or have a local script play the sound when you want to and then handle everything else on the server.
The sound needs to be parented somewhere so it can emit sound depending on its parent. For instance in workspace it will play globally. But on a part it will emit sound from that part.
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://143562367"
sound.Parent = workspace
local debounce = false
local function onTouch(part)
if debounce then
return
end
debounce = true
sound:Play()
sound.Ended:Wait()
debounce = false
end
game.Workspace.Portals.Portal1.ToS1.Touched:Connect(onTouch)