Hello I’m trying to make a Pet system, and I’m trying to do this using a Dummy, I maked a script to clone it inside the player, and I’m using MoveTo() to make it moves, but there are two issues, the first one is that I want it to stay behind the player so I tried to use MoveTo(HumanoidRootPart.Position + Vector3.new()) but it didn’t run, and the second issue is that, I tried to clone it inside the player but it always tries to get the HumenoidRootPart making move the player, so anyone has an idea ?
Script inside (ServerScriptService):
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local Dummy = game:GetService("ServerStorage").Dummy
local clone = Dummy:Clone()
local Cframe = CFrame.new(char.HumanoidRootPart.Position + Vector3.new(5,0,0))
clone.HumanoidRootPart.CFrame = Cframe
-- clone.HumanoidRootPart.Position = (char.HumanoidRootPart.Position + Vector3.new(5,0,0))
wait(2)
clone.Parent = char
end)
end)
Script Inside the Dummy:
local Part = script.Parent.Parent:WaitForChild("HumanoidRootPart")
local NPC = script.Parent
local magnitude = math.abs((Part.Position - NPC.HumanoidRootPart.Position).Magnitude)
while true do
if magnitude > 10 then
NPC.HumanoidRootPart.CFrame = Part.CFrame
elseif magnitude > 5 and magnitude < 10 then
NPC.Humanoid:MoveTo(Part.CFrame)
wait()
end
wait()
end