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

Pet Disappears Instead of Following Player?

EDIT: I made the map semi-transparent so i can see the pet, it just falls forever

I'm trying to understand how pets work in the game, so I've done a bit of experimenting, and this is what I have:

local newPet = script.Parent
newPet.CanCollide = false
newPet.Anchored = false

local petPos = Instance.new("BodyPosition", newPet)
local petGyro = Instance.new("BodyGyro", newPet)

petGyro.MaxTorque = Vector3.new(900000,900000,900000)
local owner = newPet.ID.Value
local followPosition = Vector3.new(2,2,0)

while wait(1) do
    local ownerObj = workspace:WaitForChild(owner)
    local player = game.Players:FindFirstChild(ownerObj.Name)
    local ownerPos = ownerObj.HumanoidRootPart.Position
    local stopAt = ((ownerPos - newPet.Position).magnitude - 1) * 1000
    petPos.P = stopAt
    petPos.Position = ownerPos + followPosition
    petGyro.CFrame = ownerObj.HumanoidRootPart.CFrame
end

the pet is for just me, and i have a string value of my username in the pet, when I join the pet just disappears. I've changed the pet, and it still disappears, no error messages. Please help me, I'm brand new to coding.

1 answer

✓ Accepted answer

I think i found the problem, on line 08 the BodyGyro MaxTorque are tho high, so its will result an fling problem or on the line 10, can you tell where the pet goes?

wait put a script on the pet, and after that, please tell me what the output says

local pet = script.Parent

pet.Changed:Connect(function()
	print('Location: '..pet.Position)
end)

3 comments

0

the pet is supposed to go behind me lol

0

i got this error in the output after i put in the script u told me to

0

Workspace.fieryPet.Script:4: attempt to concatenate string with Vector3

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