So I have a pretty basic script here.
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 = '14zanderbilt' while wait(0.01) do wait() local OwnerObj = workspace:WaitForChild(Owner) local OwnerPos = OwnerObj.HumanoidRootPart.Position local StopAt = ((OwnerPos - NewPet.Position).magnitude - 5) * 100000 PetPos.P = StopAt PetPos.Position = OwnerPos + Vector3.new(-3,5,3) PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame end
Tho only problem is, that when I have a too big of a "pet", it falls out of the world. Any ideas? Please note that the script is a server script, and that it works with a "light"/small "pet".
It's falling out of the world because its CanCollide property is false. This means that wherever the pet is, it will fall right through the world and after a while, it will despawn. Meaning it can't follow you.
local NewPet = script.Parent NewPet.CanCollide = true local PetPos = Instance.new("BodyPosition", NewPet) local PetGyro = Instance.new("BodyGyro", NewPet) PetGyro.MaxTorque = Vector3.new(400000,400000,400000) local Owner = '14zanderbilt' while wait(0.01) do wait() local OwnerObj = workspace:WaitForChild(Owner) local OwnerPos = OwnerObj.HumanoidRootPart.Position local StopAt = ((OwnerPos - NewPet.Position).magnitude - 5) * 100000 PetPos.P = StopAt PetPos.Position = OwnerPos + Vector3.new(-3,5,3) PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame end
I think you can use WeldConstraint. This will keep it attached.
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 = '14zanderbilt' while wait(0.01) do wait() local OwnerObj = workspace:WaitForChild(Owner) local OwnerPos = OwnerObj.HumanoidRootPart.Position local StopAt = ((OwnerPos - NewPet.Position).magnitude - 5) * 100000 local Weld = Instance.new("WeldConstraint") Weld.Parent = NewPet Weld.Part0 = NewPet Weld.Part1 = OwnerObj.HumanoidRootPart PetPos.P = StopAt PetPos.Position = OwnerPos + Vector3.new(-3,5,3) PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame end
Happy to help, b_mni.
Try creating a remote event to transport server to local and local to server. It might work because only one side of the game can see it.