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

I need help with ClickDetector in my part PetClick ?

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

0

Line 30, you shouldn't use the "and" and call the functions from seperate lines

0

what i can use

0

Replace the 30 line with givePet(Player) and add another line and write PetClick:Destroy()

0

dont work the part dont destroy the pet follow me only but the part dont destroy

0

can you vote to my question

0

Then you should try destroying the part first and then calling the give pet function

0

thank you sooooooooooooooooooooooooo much thank you

0

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

1 answer

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

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