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

Particle Emmiter on touch is not working. Why is my script not working?

So I made a script in a part that makes you get a particle emitter in your RightHand and Left Hand (R15 btw) with certain properties. When I test it, it gives a particle emitter but without my certain properties.

P.S it gives me multiple because I constantly touch it, Is there a way to stop it from doing that and only give me one? Is that the reason why it won't use specific properties?

Script:

local Part = script.Parent

local function Speed(part)
    local parent = part.Parent
    local right = Instance.new("ParticleEmitter",parent.RightHand)
    local left = Instance.new("ParticleEmitter",parent.LeftHand)
    if game.Players:GetPlayerFromCharacter(parent) then
        right.Speed = 2
        left.Speed = 2
        right.RotSpeed = 10000
        left.RotSpeed = 10000
        right.Texture = ("http://www.roblox.com/asset/?id=3442350629")
        left.Texture = ("http://www.roblox.com/asset/?id=3442350629")
        right.Rate = 100
        left.Rate = 100
        right.Rotation = 555
        left.Rotation = 555
        right.Lifetime = 3
        left.Lifetime = 3
    end
end

Part.Touched:connect(Speed)

1 answer

✓ Accepted answer

I would check to see if a player is returned by the function GetPlayerFromCharacter before inserting the ParticleEmitters into their hands:

local Part = script.Parent

local function Speed(part)
    local parent = part.Parent
    if game.Players:GetPlayerFromCharacter(parent) then
	local right = Instance.new("ParticleEmitter",parent.RightHand)
	local left = Instance.new("ParticleEmitter",parent.LeftHand)
        right.Speed = 2
        left.Speed = 2
        right.RotSpeed = 10000
        left.RotSpeed = 10000
        right.Texture = ("http://www.roblox.com/asset/?id=3442350629")
        left.Texture = ("http://www.roblox.com/asset/?id=3442350629")
        right.Rate = 100
        left.Rate = 100
        right.Rotation = 555
        left.Rotation = 555
        right.Lifetime = 3
        left.Lifetime = 3
    end
end

Part.Touched:Connect(Speed)

The reason you should check to see if you're dealing with a player's character first is because it's possible that the part that touched your part is not a member of a player's character model, and then assuming that its parent contains a LeftHand and a RightHand would be unsafe.

Also, using connect is deprecated, meaning it's outdated and has a newer version, and probably won't work in the future. Use Connect instead.

As for your issue with the properties not changing, I would just make the ParticleEmitters in Studio first, put them in your script, and simply clone them and parent them to the character's hands.

local Part = script.Parent
local particleEmitter = script:WaitForChild("ParticleEmitter")

local function Speed(part)
	local parent = part.Parent
	if game.Players:GetPlayerFromCharacter(parent) then
local clone = particleEmitter:Clone()
		clone.Parent = parent.RightHand
		local clone2 = clone:Clone()
		clone2.Parent = parent.LeftHand
	end
end

Part.Touched:Connect(Speed)

And finally, to address your issue with multiple particle emitters being inserted into the player's hands:

local Part = script.Parent
local particleEmitter = script:WaitForChild("ParticleEmitter")

local function Speed(part)
	local parent = part.Parent
	if game.Players:GetPlayerFromCharacter(parent) then
		if not parent.RightHand:FindFirstChild("ParticleEmitter") then
			local clone = particleEmitter:Clone()
			clone.Parent = parent.RightHand
			clone.Enabled = true
		end
		if not parent.LeftHand:FindFirstChild("ParticleEmitter") then
			local clone = particleEmitter:Clone()
			clone.Parent = parent.LeftHand
			clone.Enabled = true
		end
	end
end

Part.Touched:Connect(Speed)

Just check to see if a particle emitter is already there.

3 comments

0

It works but there is a problem. At the origin of the whole game (0,0,0), I see the particle emitter. How do i get rid of it?

0

I would just disable the particle emitter in Studio and then enable it once you parent it to the hands.

0

ok. thx

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