Hey! I’m having a problem with a coin collection module that I’m making. The issue is that when the player collects a coin, coin particles are supposed to pop out and the coin disappears. Currently, all of it works except for the particles, when you touch the coin the particles appear and then never go away.
I believe I have narrowed down the problem to a line of code, so take a look:
Line calling module (This function is called when a coin is touched) -
function coinSpawner.collectCurrency(part, cType, amount, player) -- The part parameter here is the coin that was touched.
coroutine.wrap(particleModule.createEffect)(part.Attachment.Collect, part.Position, .1) -- Here is where the createEffect function is called.
spawnedCurrency[part] = nil
part:Destroy()
if player.MembershipType == Enum.MembershipType.Premium then
playerModule.awardPlayer(player, amount, cType, true)
else
playerModule.awardPlayer(player, amount, cType, false)
end
end
createEffect function (The function in a module that creates an effect) -
function particleModule.createEffect(effect, position, duration)
local part = Instance.new("Part")
part.Size = Vector3.new(1, 1, 1)
part.CFrame = CFrame.new(position)
part.CanCollide = false
part.Anchored = true
part.Transparency = 1
local newEffect = effect:Clone()
newEffect.Parent = part
newEffect.Enabled = true
part.Parent = workspace
print("waiting") -- Prints
wait(duration) -- Where I believe the issue is, somehow.
print("waited") -- Doesn't print
newEffect.Enabled = false
wait(newEffect.Lifetime.Max)
part:Destroy()
end
I don’t believe this is a Luau bug or anything but it’s odd how I’m passing in the argument .1 for the duration and the wait is yielding indefinitely. This may just be a very stupid error on my part with modules and whatnot, but hopefully, someone can help me.