Hi, sorry to bother you I can’t seem to get my pet script working. Basically what its meant to do is make it show a pet follows about 5 studs behind you. Any help would be great! Thanks.
local NewPet = script.Parent
NewPet.CanCollide = false
local PetPos = Instance.new("BodyPosition", NewPet)
local PetGyro = Instance.new("BodyGyro", NewPet)
PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
local Owner = 'Pigred72'
while (1) do
wait()
local OwnerObj = workspace:WaitForChild(Owner)
local OwnerPos = OwnerObj.HumanoidRootPart.Position
local StopAt = ((OwnerObj - NewPet.Position).magnitude - 5) * 1000
PetPos.P = StopAt
PetPos.Position = OwnerPos + Vector3.new(0,10,0)
PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame
end
All the notes I have will be in the adjusted script below.
NewPet.CanCollide = false
local PetPos = Instance.new("BodyPosition", NewPet)
local PetGyro = Instance.new("BodyGyro", NewPet)
PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
local Owner = 'Pigred72'
while wait(1) do --- Changed this to wait(1) for easier readability.
local OwnerObj = workspace:WaitForChild(Owner)
local OwnerPos = OwnerObj.HumanoidRootPart --- I removed .Position for it to be easier to use in the next line
local StopAt = ((OwnerPos.Position - NewPet.Position).magnitude - 5) * 1000
--- You used OwnerObj instead of OwnerPos, which is what I assuemd you meant.
PetPos.P = StopAt
PetPos.Position = OwnerPos.Position + OwnerPos.CFrame.lookVector * - 5
--- Vector3.new(0, 10, 0) raises the part 10 studs up, instead of 5 studs behind...
--- ... I replaced it with lookVector - 5, which is 5 studs behind the character.
PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame
end
Hey! Can you provide some more info about why this isn’t working?
If your pet has a humanoid I suggest you use :MoveTo to make a smooth tween/walk to the owner.
I also suggest you define the location you want it to be at, this can be 5 studs behind the player, you can get this by using the player’s HumanoidRootPart and subtracting a Vector3 value of 5 on the X axis.
Sorry I can’t give much detailed help as I don’t know your issue! If you tell me what isn’t working, or if any errors are occuring I might be able to help a bit more.
Hi sorry for that late reply I went to bed. The pet is not humanoid its a mesh. the script is supposed to make it so when the player spawns into the game the mesh will follow it five studs behind. But what is happening right now is that when I spawn into the game the mesh is on the ground not moving.
No problem! You can increase the max force like this:
PetPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
--- math.huge is basically an infinite number, while Vector3 is the force applied in the x, y, and z planes.
More characteristics and in-depth information of BodyPosition and the main website can be found here.