Sound wont play when teleported in a function

  1. What do you want to achieve? I am trying to teleport a player and play a sound when it happens

  2. What is the issue? The sound wont play with Play() or .Playing = true or anything when its in the function… but when I play it outside of the function it works…?

  3. What solutions have you tried so far? Everything

local SoundService = game:WaitForChild("SoundService")

TeleportDie.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local RootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
		RootPart.CFrame = CFrame.new(Teleport.Position.X,Teleport.Position.Y+1,Teleport.Position.Z)
		SoundService.DeathSound:Play() --This wont play when its in the function
	end
end)

If this code is running on the server then it’s not allowed to play sounds in SoundService. The sound needs to be played from a different environment (e.g. Workspace) or from the client via a LocalScript.

Also, nitpick on the side, but use GetService if you need a top-level service, not WaitForChild.

1 Like

How would I play the sound in a local script while the function plays?

Why not a use remote event? Should work

1 Like

There’s any number of ways you can do it. I don’t know your exact use case besides assuming what you’re doing here but ideally the method you pick should be an event-based solution in some form. You can also have the client run a Touched event to play the sound, have the server inform the client to play the sound or do anything else along those lines.

1 Like