Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pet Disappears Instead of Following Player?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
the pet is supposed to go behind me lol Fauxriii 8 — 3y
0
i got this error in the output after i put in the script u told me to Fauxriii 8 — 3y
0
Workspace.fieryPet.Script:4: attempt to concatenate string with Vector3 Fauxriii 8 — 3y
Ad

Answer this question