Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

Thanks for the answer~!

This discussion is preserved as it was. New answers, comments, and votes are closed.