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)

8 comments
Line 30, you shouldn't use the "and" and call the functions from seperate lines
what i can use
Replace the 30 line with givePet(Player) and add another line and write PetClick:Destroy()
dont work the part dont destroy the pet follow me only but the part dont destroy
can you vote to my question
Then you should try destroying the part first and then calling the give pet function
thank you sooooooooooooooooooooooooo much thank you
put your answer in answers to make it correct answer thank you so much i try to make this for months thank you you are the best thank you sooooooo much