Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Pet not rotating?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

Made a little pet script, however, it won't be able to rotate.

local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:wait()
    torso = char:WaitForChild('Torso')
local ServerStorage = game:GetService('ServerStorage')

    Pets = ServerStorage:WaitForChild('Pets')
    dog = Pets:WaitForChild('Annoying Dog')
    oldrot = Vector3.new(90,180,90) -- Rotation

    dog.Parent = char

        Gyro = Instance.new('BodyGyro',dog)
            while wait() do
                Gyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
                    oldpos = torso.CFrame * CFrame.new(0,-2,-4)
                        dog.Rotation = Vector3.new(90,180,90)
                        dog.Rotation = oldrot
                        dog.CFrame = oldpos
                Gyro.CFrame = torso.CFrame
                                                end

It works, just rotation property of part isn't working. pet is a union

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
8 years ago

It seems like you want the dog to hover around the player's head.

Use a combination of BodyPositions and BodyGyros.

local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:wait()
local torso = char:WaitForChild('Torso')
local head = char:WaitForChild('Head')
local ServerStorage = game:GetService('ServerStorage')

local Pets = ServerStorage:WaitForChild('Pets')
local dog = Pets:WaitForChild('Annoying Dog')

local newpet = dog:Clone()
newpet.Parent = workspace

local bgyro = Instance.new('BodyGyro', newpet)
bgyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

local bpos = Instance.new('BodyPosition', newpet)
bpos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

while wait() do
    bpos.Position = (head.CFrame * CFrame.new(2, 2, 1)).p -- makes the pet move relative to the head
    bgyro.CFrame = head.CFrame -- makes the pet rotate with the player
    bgyro.CFrame = bgyro.CFrame * CFrame.Angles(-math.pi/2, 0, 0) -- the dog was apparently oriented wrong. This corrects for it.
end
Ad

Answer this question