I created a script that works when you touched the part, ( CanTouch should be set to true), and it creates a parts with emitters that should emit only ONCE.
here is the code:
Whenever i touch the part emitter emits a lot of times and i have no idea why. I have tried to change the script a lot of times but i still can’t figure out the problem.
Could you show us an example of what the intended result looks like, versus what is actually happening? Just so it’s easier to gauge where the problem lies.
Also, you should use Debris and add those part instances so they don’t clog up workspace.
Debris:AddItem(Instance,TimeBeforeDestroy)
…Another edit…
If you are using the positions table as a random position picker you can also simply take one position and use math.random() to add or remove position from x,y,z
e.g:
Instance.Position += Vector3.new(math.random(-5,5)/10,math.random(-5,5)/10,math.random(-5,5)/10)
--math.random(-5,5)/10 returns a number from -.5 to .5
P.S. you don’t need to disable the ParticleEmitter after using :Emit() lol
"local trigger = script.Parent
local particle = game.Workspace.DEPW:WaitForChild(“ParticleEmitter”)
local childName = “pos”
local parent = workspace
local children = parent:GetChildren()
local positions = {}
for _, child in ipairs(children) do
if child.Name == childName then
table.insert(positions, child.Position)
end
end
local cooldown = 5
local function onCanTouch()
if trigger.CanTouch then
for _, position in ipairs(positions) do
local part = Instance.new(“Part”)
part.Transparency = 1
part.Anchored = true
part.Parent = workspace
part.Position = position
local emitter = particle:Clone()
emitter.Parent = part
emitter:Emit(1)
emitter.Enabled = false
end
trigger.CanTouch = false
task.wait(cooldown, function()
trigger.CanTouch = true
end)
end
The code seems correct so far, i’m not sure why it’s firing when CanTouch is false, it’s impossible. Maybe you connected the onCanTouch function on another part?