You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to know how to solve this problem.
What is the issue? Include screenshots / videos if possible!
I have a coin when you touch it, it plays a sound and then destroy. But somehow it doesn’t work robloxapp-20230814-1325177.wmv (442.8 KB)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
When I remove the :Destroy() it does work but when I added it again the sound doesn’t play
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local coin = script.Parent
local touchPart = script.Parent.Coin
local debounce = false
touchPart.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if debounce == false then
script.Parent.Sound:Play()
debounce = true
end
end
script.Parent:Destroy()
end)
local coin = script.Parent
local touchPart = script.Parent.Coin
local debounce = false
touchPart.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if debounce == false then
script.Parent.Sound:Play()
script.Parent.Sound:Stop()
debounce = true
end
end
wait(2)
script.Parent:Destroy()
end)
Even if I am not using the debounce, the sound isn’t play
local coin = script.Parent
local touchPart = script.Parent.Coin
local debounce = false
touchPart.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
script.Parent.Sound:Play()
end
script.Parent:Destroy()
end)
the model is being destroying just after the sound is playing write :
touchPart.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
script.Parent.Sound:Play()
script.Parent.Sound.Ended:Wait()
script.Parent:Destroy()
end
end)
I don’t know why but the sound still repeat 4 times and destroyed when I have my debounce (sorry I am new)
local coin = script.Parent
local touchPart = script.Parent.Coin
local debounce = false
touchPart.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if debounce == false then
script.Parent.Sound:Play()
script.Parent.Sound.Ended:Wait()
debounce = true
end
script.Parent:Destroy()
end
end)
touchPart.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and not debounce then
debounce = true
script.Parent.Sound:Play()
script.Parent.Sound.Ended:Wait()
script.Parent:Destroy()
debounce = false
end
end)