After learning about body gyros and body positions at developer.Roblox.com, I wrote some code to give a player a pet and to my surprise it worked…then it didn’t. The pet does not move at all! I looked around online and found that my code was seemingly identical to other peoples. So I wondered, why is mine not working? I tried comparing my code with the other peoples but I found no difference. Please help!
local pet = script.Parent
function GivePet(player)
if player then
if player.Character then
local Character = player.Character
local humanoid = Character:WaitForChild("HumanoidRootPart")
local newPet = pet:Clone()
newPet.CanCollide = false
newPet.BrickColor = BrickColor.new("Baby blue")
newPet.Transparency = 0
newPet.Parent = player.Character
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
local bodyPos = Instance.new("BodyPosition")
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyGyro.Parent = newPet
bodyPos.Parent = newPet
while wait() do
print("Moving...")
bodyPos.Position = humanoid.Position + Vector3.new(2,2,3)
bodyGyro.CFrame = player.character.HumanoidRootPart.CFrame
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
GivePet(player)
end)
end)
The pet is in the workspace and the code is in the pet.