I have part named PetClick I want if player click on the part the pet follow them and I want also delete PetClick part if i click on part the pet follow player but the part dont delete this is my script
local pet = script.Parent function givePet (player) if player then local character = player.Character if character then local humRootPart = character.HumanoidRootPart local newPet = pet:Clone() newPet.Parent = character local bodyPos = Instance.new("BodyPosition", newPet) bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge) local bodyGyro = Instance.new("BodyGyro", newPet) bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge) while wait() do bodyPos.Position = humRootPart.Position + Vector3.new(2, 2, 3) bodyGyro.CFrame = humRootPart.CFrame end end end end local PetClick = game.Workspace.PetClick game.Workspace.PetClick.ClickDetector.MouseClick:Connect(function(player) givePet(player) and PetClick:Destroy() end)
Replace the 30 line with givePet(Player) and add another line and write PetClick:Destroy() Then you should try destroying the part first and then calling the give pet function Answers by marijus06