How to make tool make sound after respawning?

Can anybody help me on this script? Since I want it so when you hold the tool and you click, it will player a sound, and it works! But when you reset your character and spawn back and try the tool again, it no work.

Script:

local tool = script.Parent
local sound = game.ReplicatedStorage:FindFirstChild("QuackSound") -- Sound is stored in ReplicatedStorage

if not sound then
	warn("QuackSound not found in ReplicatedStorage!")
	return
end

-- Play the quack sound when the tool is activated (clicked)
tool.Activated:Connect(function()
	local clonedSound = sound:Clone() -- Clone the sound so it doesn't get deleted
	clonedSound.Parent = tool.Handle -- Parent it to the tool's handle or workspace
	clonedSound:Play() -- Play the sound
	clonedSound.Ended:Connect(function() clonedSound:Destroy() end) -- Clean up sound after it finishes
end)

-- Ensure sound is accessible after respawn
tool.Equipped:Connect(function()
	if not game.ReplicatedStorage:FindFirstChild("QuackSound") then
		warn("QuackSound was removed from ReplicatedStorage!")
	end
end)

Me personally, i store my sounds inside the SoundService simply because it makes more sense. Try that maybe?

Also, you don’t need to clone and destroy sounds. You can simply have them stored, and play them when needed. They take up so little storage that they won’t cause any extra lag and deleting the sounds after they are used can simply just cause more problems

Hi I tried what you said and it didn’t work, but here is the script, since I feel like I might have done something wrong.

local tool = script.Parent
local sound = game.SoundService:FindFirstChild("QuackSound") -- Sound stored in SoundService

if not sound then
	warn("QuackSound not found in SoundService!")
	return
end

tool.Activated:Connect(function()
	sound:Play() 
end)

tool.Equipped:Connect(function()
	if not game.SoundService:FindFirstChild("QuackSound") then
		warn("QuackSound was removed from SoundService!")
	end
end)

I would do

SoundService = game:GetService('SoundService')

tool.Activated:Connect(function()
	SoundService.sound:Play() 
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.