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

How to delete a part from a character using a text button and a mousebuttonclick2 function?

Asked by
Echtic 128
6 years ago

I made an inventory GUI and each time u left click a certain text button a pet appears and follows you.Now i want that pet deleted when player right clicks the same text button how do i do that? I have already tried something but it didn't work,here is the whole script(the upper part works)

local target = game.ReplicatedStorage.AlphaPet

script.Parent.MouseButton1Click:connect(function()
    if game.Players.LocalPlayer.Character:FindFirstChild("AlphaPet")== nil then
    local pet = target:Clone()
    pet.Parent = game.Players.LocalPlayer.Character
    pet.LocalScript.Disabled = false


    end
end)

script.Parent.MouseButton2Click:connect(function()
    if game.Players.LocalPlayer.Character:FindFirstChild("AlphaPet")== true then
        local pet = target:Clone()
        pet.Parent = game.ServerStorage.Junk
        pet.LocalScript.Disabled = true

    end

end)

1 answer

Log in to vote
0
Answered by 6 years ago
target = game.ReplicatedStorage.AlphaPet

script.Parent.MouseButton1Click:connect(function()
    if game.Players.LocalPlayer.Character:FindFirstChild("AlphaPet")== nil then
         local pet = target:Clone()
         pet.Parent = game.Players.LocalPlayer.Character
         pet.LocalScript.Disabled = false


    end
end)

script.Parent.MouseButton2Click:connect(function()
    if game.Players.LocalPlayer.Character:FindFirstChild("AlphaPet")== true then
        local pet = target:Clone()
        pet:Destroy() -- COMPLETELY removes it
        pet.LocalScript.Disabled = true

    end

end)

Stop using local variables. THEY DO NOT WORK.

Ad

Answer this question