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

How do i make a script delete these clones with the same key?

Asked by
Echtic 128
5 years ago

Here's the script:

local Player = script.Parent.Parent
local me = Player
local mouse = Player:GetMouse()
active = false

mouse.KeyDown:connect(function(key)
if key == "r" then

    local ra = me.Character:FindFirstChild("Right Arm")
    local la = me.Character:FindFirstChild("Left Arm")
    local tr = me.Character:FindFirstChild("Torso")
    local ll = me.Character:FindFirstChild("Left Leg")
    local rl = me.Character:FindFirstChild("Right Leg")

    local aura1 = game.ReplicatedStorage.YamiA:Clone()
    aura1.Name = "aura1"
    aura1.Parent = ra
    --------
    local aura2 = game.ReplicatedStorage.YamiA:Clone()
    aura2.Name = "aura2"
    aura2.Parent = la
    --------
    local aura3 = game.ReplicatedStorage.YamiA:Clone()
    aura3.Name = "aura3"
    aura3.Parent = tr
    --------
    local aura4 = game.ReplicatedStorage.YamiA:Clone()
    aura4.Name = "aura4"
    aura4.Parent = ll
    --------
    local aura5 = game.ReplicatedStorage.YamiA:Clone()
    aura5.Name = "aura5"
    aura5.Parent = rl


    end



end)
0
KeyDown is deprecated, so is connect. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
Problem Solution
Mouse.KeyDown is deprecated Switch to UserInputService or ContextActionService
connect is deprecated Switch to Connect

You’re welcome.

local yami = game:GetService("ReplicatedStorage").YamiA
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService"UserInputService"
local enabled = false
local names = {
    "Torso", 
    "Left Arm",
    "Right Arm", 
    "Left Leg", 
    "Right Leg"
}


UIS.InputBegan:Connect(function(key, gpe)
    if gpe then
        return
    end

    if key.KeyCode == Enum.KeyCode.R then
        enabled = not enabled

        if enabled then
            for _, v in pairs(char:GetChildren())) do
                if v:IsA"BasePart" and names[v.Name] then
                    yami:Clone().Parent = v
                end
            end
        end

        if not enabled then
            for _, v in pairs(char:GetChildren()) do
                if v:FindFirstChild"YamiA" then
                    v.YamiA:Destroy()
                end
            end

        end
    end
end)
Ad

Answer this question