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

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

Asked by
rexpex 45
7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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)
0
thanks, this is a debounce right? rexpex 45 — 7y
0
Correct. Goulstem 8144 — 7y
Ad

Answer this question