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

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

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 comment

1 answer

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.

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