Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how can i change this script to where the particles can only appear once every 20 seconds on touch?

Asked by 8 years ago
S=script.Parent.ParticleEmitter 
function onTouched(hit) 
wait(.1) 
S = script.Parent.ParticleEmitter:clone() 
S.Parent=hit.Parent.Torso 
wait(.1) 
S.Enabled = true 
wait(3) 

S.Parent.ParticleEmitter:remove()



end 
script.Parent.Touched:connect(onTouched) 

i've tried many different things to get this script to make the particles appear once every 20 seconds, but no luck so far

i could use some help on this

0
use a debounce but wait 20 till setting it to be able to work again bubbaman73 143 — 8y

1 answer

Log in to vote
1
Answered by
0_0 70
8 years ago

Hi there!

local PARTICLE_EMITTER = script.Parent.ParticleEmitter -- Declaring the ParticleEmitter.
local EMIT_TIME = 3 -- How long the particle will emit for until it gets destroyed.
local COOLDOWN = 20 -- 20 second cooldown.
local ENABLED = true -- Debounce used here to make sure the ParticleEmitter has a cooldown.

script.Parent.Touched:connect(function(hit) -- Touched connection, hit being what 3D object hit it.
    if ENABLED and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Torso") then -- If enabled is true and human.
        ENABLED = false -- Here we set the variable 'ENABLED' to false to prevent the .Touched event from being fired until we set it to true, acting as a debounce and allows us to have some time before the next .Touched event is able to be called.
        local clone = PARTICLE_EMITTER:Clone() -- Saving a copy of the ParticleEmitter.
        clone.Enabled = true -- Making the ParticleEmitter able to emit particles.
        clone.Parent = hit.Parent.Torso -- Making the parent of the clone we made to the player's torso.
        wait(EMIT_TIME) -- Wait specified time in the EMIT_TIME variable we set
        clone:Destroy() -- :remove() is deprecated, It's good practise to use :Destroy(). As the method implies, it destroys the clone.
        wait(COOLDOWN) -- Wait until the specified amount of time of your cooldown variable.
        ENABLED = true -- Set enabled back to true so the .Touched can continue running and the cycle continues.
    end
end)

Best of luck, I commented everything around my code to try and help you understand how to accomplish this, if you need any further assistance on this then feel free to comment below and I'll try to get back to you as soon as possible, thanks.

Ad

Answer this question