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

How do i turn this ParticleEmitter on my Hand Off and on?

Im using R15 for a game im making but it requires particle emitters. I made a script that allows me to turn it on with a keyDown event but i dont know how to turn it off. Here is the script

player = game.Players.LocalPlayer
mouse = player:GetMouse()




function KeyDown(key)
	key = key:lower()
	local hotkey = script.hawtkey
	local particle = player.Character.RightHand:findFirstChild("ParticleEmitter")
	if key == hotkey.Value then
		local sparkel = Instance.new("ParticleEmitter")
		sparkel.Texture = "http://www.roblox.com/asset/?id=492009091"
	   sparkel.Size = NumberSequence.new(1)
	   sparkel.Rate = 200
	   sparkel.Speed = NumberRange.new(20)
	   sparkel.Lifetime = NumberRange.new(50)
	   sparkel.Parent = player.Character.RightHand
	if particle == true then
		player.Character.RightHand.Enabled = false
		
		
		
	end
		
	end
end

mouse.KeyDown:connect(KeyDown)

1 answer

✓ Accepted answer

In order to turn the effect off, you need to make a variable for the effect's current status.

This way, when you press the key you can check the status. If it is on, turn it off.. and if its off, turn it on.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local status = false; --Current status of effect

function KeyDown(key)
	key = key:lower()
	local hotkey = script.hawtkey
	local particle = player.Character.RightHand:findFirstChild("ParticleEmitter")
	if key == hotkey.Value then
		if not status then --Check status
			--If it is off, turn on
			status = true;
			local sparkel = Instance.new("ParticleEmitter")
			sparkel.Texture = "http://www.roblox.com/asset/?id=492009091"
			sparkel.Size = NumberSequence.new(1)
			sparkel.Rate = 200
			sparkel.Speed = NumberRange.new(20)
			sparkel.Lifetime = NumberRange.new(50)
			sparkel.Parent = player.Character.RightHand
			sparkel.Name = "Effect";
		else --If if is on, turn off.
			local sparkel = player.Character.RightHand:FindFirstChild("Effect");
			if sparkel then
				sparkel:Destroy();
			end
			status = false;
		end
	end
end

mouse.KeyDown:connect(KeyDown)

2 comments

0

thanks, this is a debounce right?

0

Correct.

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