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

How could I fix my on Touch do Particle Emmitter script?

Asked by 7 years ago

The problem is that I tried to make so if you already have one you can't have another one (Particle Emitter)..

Heres my script :

Part = script.Parent

Part.Touched:connect(function(hit) -- Use the touched event on a brick( hit refers to the part or brick that is hit by 'Part')
    if hit.Parent:FindFirstChild('Humanoid') then -- If there is a humanoid it is more likely to be a player
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent) 
        if Player ~= nil then -- checks to see if the model or Parent is actually a player
            for _, child in pairs(hit.Parent.UpperTorso:GetChildren()) do
            if child:IsA("ParticleEmitter") then
else
                local Fire = game.ServerStorage.Fire:Clone()
            Fire.Parent = hit.Parent.UpperTorso
            Fire.sound:Play()


            hit.Parent.Humanoid.WalkSpeed = 30
end

Thanks for the help!

1 answer

Log in to vote
0
Answered by 7 years ago

There are few things inside Player's UpperTorso and by doing this :

for _, child in pairs(hit.Parent.UpperTorso:GetChildren()) do
            if child:IsA("ParticleEmitter") then
else
                local Fire = game.ServerStorage.Fire:Clone()
            Fire.Parent = hit.Parent.UpperTorso
            Fire.sound:Play()

You create a loop over all the Player's UpperTorso childrens The loop won't stop when it find ParticleEmmiter. It will just ignore it.

It will create the "Fire" as many times as there are childrens.

You should write it like that:

Part = script.Parent

Part.Touched:connect(function(hit) -- Use the touched event on a brick( hit refers to the part or brick that is hit by 'Part')
    if hit.Parent:FindFirstChild('Humanoid') then -- If there is a humanoid it is more likely to be a player
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent) 
        if Player ~= nil then -- checks to see if the model or Parent is actually a player
   if Player.Character.UpperTorso:FindFirstChild("Fire") then --- The part that checks if there is ParticleEmmiter already --

else
                local Fire = game.ServerStorage.Fire:Clone()
            Fire.Parent = hit.Parent.UpperTorso
            Fire.sound:Play()


            hit.Parent.Humanoid.WalkSpeed = 30
end
end
end
end)
0
Thanks for the answer~! starchip12 6 — 7y
Ad

Answer this question