Hey, so i tried to make a particle giver part but it gives the particles multiple times and the debounce doesnt seem to work i would really appreciate if someone can fix it for me (i would really like that instead of a particle giver part its a part that gives a particle once you click preferably if its toggleable, the click can be replaced with proximity prompt but the particle giver part its still ok altough if ur doing the another ones i would really appreciate if its in a downloadable place or model, thanks.)
heres the code:
function onTouched(hit)
local db = false
local human = hit.Parent:findFirstChild("Humanoid")
if db then return end
db = true
script.Parent.ParticleEmitter:clone().Parent = human.Parent:findFirstChild("Head")
script.Parent.ParticleEmitter:clone().Parent = human.Parent:findFirstChild("Left Leg")
script.Parent.ParticleEmitter:clone().Parent = human.Parent:findFirstChild("Left Arm")
script.Parent.ParticleEmitter:clone().Parent = human.Parent:findFirstChild("Right Arm")
script.Parent.ParticleEmitter:clone().Parent = human.Parent:findFirstChild("Right Leg")
script.Parent.ParticleEmitter:clone().Parent = human.Parent:findFirstChild("Torso")
script.Parent.ParticleEmitter2:clone().Parent = human.Parent:findFirstChild("Head")
script.Parent.ParticleEmitter2:clone().Parent = human.Parent:findFirstChild("Left Leg")
script.Parent.ParticleEmitter2:clone().Parent = human.Parent:findFirstChild("Left Arm")
script.Parent.ParticleEmitter2:clone().Parent = human.Parent:findFirstChild("Right Arm")
script.Parent.ParticleEmitter2:clone().Parent = human.Parent:findFirstChild("Right Leg")
script.Parent.ParticleEmitter2:clone().Parent = human.Parent:findFirstChild("Torso")
wait(2.5)
db = false
end
script.Parent.Touched:connect(onTouched)
1- Instead of wait, use task.wait().
2- You could shortn all these lines with a simple for loop.
3- Try this one :
function onTouched(hit)
local db = false
local human = hit.Parent:findFirstChild("Humanoid")
if db == false then
db = true
for _,bodyPart in pairs(hit.Parent:GetChildren()) do
if bodyPart:IsA("BasePart") then
if not bodyPart:FindFirstChild("ParticleEmitter") then
local clone = script.Parent.ParticleEmitter:Clone()
clone.Parent = bodyPart
end
end
end
task.wait(2.5)
db = false
end
end
script.Parent.Touched:connect(onTouched)
function onTouched(hit)
local db = false
local human = hit.Parent:findFirstChild("Humanoid")
if db == false then
db = true
for _,bodyPart in pairs(hit.Parent:GetChildren()) do
if bodyPart:IsA("BasePart") then
if not bodyPart:FindFirstChild("ParticleEmitter") then
local clone = script.Parent.ParticleEmitter:Clone()
clone.Parent = bodyPart
end
end
task.wait(1.2)
end
task.wait(2.5)
db = false
end
end
script.Parent.Touched:connect(onTouched)
Just check if particle exists in body parts or not,
Also put db above the ontouch event, the debounce is setting to false whenever someone is touching the part, if its a server script then I suggest you to use db as table.
I also don’t think using wait, in a server script is a good thing, i prefer you to use delay() in touch events for debounce.
local db = {}
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if not db[player] then
table.insert(db,player)
for i,part in pairs(player.Character:GetChildren()) do
if part:IsA("BasePart") then
if not part:FindFirstChild("ParticleEmitter") then
script.Parent.ParticleEmitter:clone().Parent = part
end
if not part:FindFirstChild("ParticleEmitter2") then
script.Parent.ParticleEmitter2:clone().Parent = part
end
end
end
delay(2.5,function() table.remove(db,table.find(db,player)) end)
end
end
end
script.Parent.Touched:connect(onTouched)
You are doing the same, you are setting DB variable when the part is touched, before the touched function.
And use bool value in debounce only in local scripts!
Since whenever a player hits a part Every player have to wait 2.5 seconds to touch that part again because of db, instead if you make it a table this will no longer be an issue.
Thanks a lot to both of you guys, really appreciated i would give the solution checkmark to both of u but i cant still really appreciated its a great help.