Help Please Pet Movement Not Working
code:
local plr = game.Players.LocalPlayer
local chr = plr.Character
local LERPLEVEL = .1;
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(newPet)
local function UpdatePos()
local petCframe = newPet.PrimaryPart.CFrame
local characterCframe = chr["HumanoidRootPart"].CFrame
local posY = 0
local RayDirection = newPet["RayPart"].CFrame.LookVector * 10
local newRay = Ray.new(newPet["RayPart"].Position, RayDirection)
local hit, position = game.Workspace:FindPartOnRay(newRay, newPet["RayPart"])
if hit then
posY = newPet.PrimaryPart.Position.Y + newPet.PrimaryPart.Size.Y + hit.Size.Y
else
print("Error Player LookVector Not Finded A Part!")
end
local targetCframe = characterCframe + Vector3.new(3,posY - 3,0)
local newCframe = petCframe:Lerp(targetCframe, LERPLEVEL)
newPet:SetPrimaryPartCFrame(newCframe)
end
game:GetService("RunService").Heartbeat:Connect(function() UpdatePos() end)
end)