I’m having trouble trying to get a part to spawn in, and then follow the character, but keep it along the ground (not floating or inside the ground)
Here’s what it currently looks like:
When I spawn it in, it goes into the ground, and when I move, it moves up and stays in the air. The red part is the HumanoidRootPart.
Server code to place the item in
local function Equip(player, pet)
-- Check for pet in folder
local EquippedPet = Pets:FindFirstChild(pet)
if not EquippedPet then return end
--/// EDIT Check to make sure player owns pet
-- Make sure player doesn't already have a pet equipped
if PetContainer:FindFirstChild(player.Name) then
-- If they do, unequip their current pet
Unequip(player, pet)
end
-- Clone pet
local ClonedPet = EquippedPet:Clone()
ClonedPet.Name = player.Name
-- Set position
ClonedPet:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(5, 0, 0))
-- Parent
ClonedPet.Parent = PetContainer
-- Set Network owner
ClonedPet.PrimaryPart:SetNetworkOwner(player)
end
Client code to move it
-- Render and make pet follow players
local function RenderPet(pet)
-- Get the TargetPlayer
local TargetPlayer = Players[pet.Name]
if not TargetPlayer then return end
-- Get the TargetCharacter
local TargetCharacter = TargetPlayer.Character
if not TargetCharacter then return end
-- Wait for PrimaryPart
pet:WaitForChild('HumanoidRootPart')
-- Get Body's
local BodyGyro = pet.HumanoidRootPart.BodyGyro
local BodyPosition = pet.HumanoidRootPart.BodyPosition
local function MovePet()
-- Check if player is 15 studs away from pet
local Distance = (TargetCharacter.HumanoidRootPart.Position - pet.HumanoidRootPart.Position).Magnitude
if Distance < 15 then return end
-- If so, we want to keep moving the pet, until the player has come to a complete stop
while TargetCharacter.Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) do
BodyGyro.CFrame = TargetCharacter.HumanoidRootPart.CFrame
BodyPosition.Position = CFrame.new(TargetCharacter.HumanoidRootPart.CFrame * Vector3.new(5, 0, 0)).Position
wait()
end
end
RunService.RenderStepped:Connect(MovePet)
end
So ye, I just want it to stay along the ground. Originally I was gonna do like ‘-2’ from the HRP, but that would only work for players who haven’t edited their heights. I need it to always be along the ground, irrelevant of player heights