SoundEffect of the teleportation part only

I scripted a teleportation script. How do I ensure that the sound effect plays only a single-time, when the part is being touched?

local TeleportPosition = game.Workspace.TeleportPosition

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") thenalways an Humanoid
		if game:GetService("Players"):FindFirstChild(hit.Parent.Name) then
			game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPosition.CFrame
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		game.Workspace.teleporting:Play()
	end
end)

You can use the IsPlaying property to play the sound only if it’s not playing

script.Parent.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if workspace.teleporting.IsPlaying then return end
		game.Workspace.teleporting:Play()
	end
end)

It should prevent it from being played more than once

1 Like

iT WoRked, Thanks man! I will mark this as a solution so other people know this topic has been solve.

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!