Sound not playing when :Play() is called

I’m making a simple module for my game called StillSound, where I can give the module a Sound instance and a Vector3 position and it will play a sound at that position. For some reason, the sound doesn’t play. Here is my code:

local StillSound = {}

function StillSound:Play(sound, position)
	local stillSound = Instance.new("Part")
	sound:Clone().Parent = stillSound
	stillSound.Transparency = .5
	stillSound.Anchored = true
	stillSound.CanCollide = false
	stillSound.CanQuery = false
	stillSound.CanTouch = false
	stillSound.Position = position
	stillSound.Name = "StillSound"
	stillSound.Parent = workspace
	sound:Play()
	task.spawn(function()
		sound.Ended:Wait()
		if stillSound then
			stillSound:Destroy()
		end
	end)
end

return StillSound

And what happens in game:


You can see it doesn’t play or does play for a split second before stopping. It should play a sword damage sound. How can I fix this?
Any help is appreciated.

What I can read:
Cloned sound’s parent is stillSound, but tried to play original sound.

Make local value to save cloned sound and play from local value instead.

1 Like
local StillSound = {}

function StillSound:Play(sound, position)
	local stillSound = Instance.new("Part")
	local newsound = sound:Clone().Parent = stillSound
	stillSound.Transparency = .5
	stillSound.Anchored = true
	stillSound.CanCollide = false
	stillSound.CanQuery = false
	stillSound.CanTouch = false
	stillSound.Position = position
	stillSound.Name = "StillSound"
	stillSound.Parent = workspace
	newsound:Play()
	task.spawn(function()
		sound.Ended:Wait()
		if stillSound then
			stillSound:Destroy()
		end
	end)
end

return StillSound
1 Like