Coin Sound Problem

The sound always plays after it comes back, what should I do

local coinPart = script.Parent
local toggle = false
local amount = 100

coinPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) ~= nil and not toggle then
coinPart.Sound:Play()
toggle = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats = player:FindFirstChild(“leaderstats”)
local coins = leaderstats.Gold

	coins.Value = coins.Value + amount
	
	local coinClone = coinPart:Clone()
	coinPart:Destroy()
	wait(10)
	coinClone.Parent = workspace
	toggle = false
end

end)

if coinPart is destroyed then the whole script will also destroy. So wait(10) won’t work. Also what do you mean by

It has been corrected, I actually wanted to say the sound always plays after it comes back

how about this script

local coinPart = script.Parent
local toggle = false
local amount = 100

coinPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) ~= nil and not toggle then
coinPart.Sound:Play()
toggle = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats = player:FindFirstChild(“leaderstats”)
local coins = leaderstats.Gold

	coins.Value = coins.Value + amount
	
	coinPart.Transparency = 1
	wait(10)
	coinPart.Transparency = 0
	toggle = false
end

end)

I don’t think there is anything wrong with the script. Make sure the Looped property of the sound is false
Screenshot_44

1 Like