Strange, works for me?
Coin.rbxl (44.8 KB)
Yeah I agree with @PersonifiedPizza
It works in the place file you sent, which means it’s probably something that has to do with your place specifically or how you spawn in the coins.
Edit:
Are you using custom characters?
Okay well this is the spawning script
-- Functions
local ZoneModule = require(game:GetService("ReplicatedStorage").Zone)
local CoinZone = ZoneModule.new(game.Workspace:WaitForChild("Folders"):WaitForChild("_MAPS"):WaitForChild("Spawn"):WaitForChild("_COINSPAWNAREA"):WaitForChild("Other Coins"))
local coin = game.ServerStorage.SpawnCoins:WaitForChild("Coins2")
--
local Coin2Amount = 0
--
local MaxCoinAmount = 10
-- coin1
while task.wait(1) do
if Coin2Amount <= MaxCoinAmount then
Coin2Amount = Coin2Amount + 1
local coinclone = coin:Clone()
coinclone.Position = CoinZone:getRandomPoint()
coinclone.Parent = game.Workspace.Folders._MAPS.Spawn._COINS.Coins
coinclone.Touched:Connect(function(hit)
--print("collected2")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + math.random(2.4, 3) * player.Multipliers.CoinMultiplier.Value
--game.Workspace.Folders._OTHERSFX.CoinCollect:Play()
Coin2Amount = Coin2Amount - 1
coinclone:Destroy()
end)
wait(math.random(2, 4))
end
end
Is this other touched event working? You could just do:
-- Functions
local ZoneModule = require(game:GetService("ReplicatedStorage").Zone)
local CoinZone = ZoneModule.new(game.Workspace:WaitForChild("Folders"):WaitForChild("_MAPS"):WaitForChild("Spawn"):WaitForChild("_COINSPAWNAREA"):WaitForChild("Other Coins"))
local coin = game.ServerStorage.SpawnCoins:WaitForChild("Coins2")
--
local Coin2Amount = 0
--
local MaxCoinAmount = 10
-- coin1
while task.wait(1) do
if Coin2Amount <= MaxCoinAmount then
Coin2Amount = Coin2Amount + 1
local coinclone = coin:Clone()
coinclone.Position = CoinZone:getRandomPoint()
coinclone.Parent = game.Workspace.Folders._MAPS.Spawn._COINS.Coins
coinclone.Touched:Connect(function(hit)
--print("collected2")
-- Added code to play the sound:
coinclone.Sound:Play()
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + math.random(2.4, 3) * player.Multipliers.CoinMultiplier.Value
--game.Workspace.Folders._OTHERSFX.CoinCollect:Play()
Coin2Amount = Coin2Amount - 1
coinclone:Destroy()
end)
wait(math.random(2, 4))
end
end
Edit:
Wait are you creating connections to Touched every second? That might be the problem, you only need one. Once you dont need it just call :Disconnect on the connection.
Nvm you create a coin every second.
Oh it might be because you play the sound as you destroy the coin
That doesn’t seem to play it either.
Oh yea that would make sense. Shall I put a wait just to see?
Oh, that could be. To combat this issue, remove the :Play line, and enable “PlayOnRemove”
@Annexsohn
Try enabling “PlayOnRemove” on the sound
https://developer.roblox.com/en-us/api-reference/property/Sound/PlayOnRemove
Okay, I think I know what the problem is: the sound is played as the coin is destroyed, so the sound is destroyed too. I’m not sure if you can play sounds then destroy them.
I’m going to test this code:
-- Functions
local ZoneModule = require(game:GetService("ReplicatedStorage").Zone)
local CoinZone = ZoneModule.new(game.Workspace:WaitForChild("Folders"):WaitForChild("_MAPS"):WaitForChild("Spawn"):WaitForChild("_COINSPAWNAREA"):WaitForChild("Other Coins"))
local coin = game.ServerStorage.SpawnCoins:WaitForChild("Coins2")
--
local Coin2Amount = 0
--
local MaxCoinAmount = 10
-- coin1
while task.wait(1) do
if Coin2Amount <= MaxCoinAmount then
Coin2Amount = Coin2Amount + 1
local coinclone = coin:Clone()
coinclone.Position = CoinZone:getRandomPoint()
coinclone.Parent = game.Workspace.Folders._MAPS.Spawn._COINS.Coins
coinclone.Touched:Connect(function(hit)
--print("collected2")
-- Added code to play the sound:
local part = Instance.new("Part")
part.CanCollide = false
part.Transparency = 0
part.Position = coinclone.Position
part.Anchored = true
part.Parent = game.Workspace
local soundClone = coinclone.Sound:Clone()
soundClone.Parent = part
part.Sound:Play()
local soundEndedConnection
soundEndedConnection = part.Sound.Ended:Connect(function()
soundEndedConnection:Disconnect()
part:Destroy()
end)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + math.random(2.4, 3) * player.Multipliers.CoinMultiplier.Value
--game.Workspace.Folders._OTHERSFX.CoinCollect:Play()
Coin2Amount = Coin2Amount - 1
coinclone:Destroy()
end)
wait(math.random(2, 4))
end
end
Edit:
Yeah, PlayOnRemove is a clever solution, I’d forgotten about that property! Glad that works
No… I just tried to add a 5 second wait to destroy it, and it still doesn’t seem to play the sound…
I seem to still be able to hear it anywhere. It seemed to not fix my issue
It seemed to did play the sound, but I can still hear it anywhere… (the playonremove)
Hmm, very odd. Do you mind giving us a new place file with what you did with the play on remove?
I just enabled the property and removed that line of code to play it
Works fine, hard to notice though. I compared from zoomed in to out (fully) and it is noticeable.
I know you said it is not about the roll off distance, but in this case, I think it is.
Yea I fell like I hear a difference too, but I teleported across the map and I could still hear it on the other profile.
I feel like this is a roblox bug, not 100% sure yet though. Still testing
Oh yea it does work actually, I tp’d away to another world and I was not able to hear it.
Yeah, you might have to make the roll off distance like super low, idk why you have to do this, but I’m glad this solved your issue (I think)
I hope it does fix this. I will be testing around in a LocalServer on Roblox Studio finding the best Distance! I appreciate your help, and especially @PersonifiedPizza help!