Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I Set the MaxTorque of a BodyGyro to a humanoids LookVector?

I've been trying to set the MaxTorque of the BodyGyro to a humanoid LookVector for a while now but i can't seen to figure it out. This my whole script, thank you for helping me.

local UIS = game:GetService("UserInputService")
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
char = Player.Character
hum = char.Humanoid
root = char.HumanoidRootPart
local holdingUKey = false


UIS.InputBegan:Connect(function(inputObject) 
    if(inputObject.KeyCode==Enum.KeyCode.U)then
        holdingUKey = true
        while holdingUKey do
        local bp = Instance.new("BodyPosition")
        bp.Parent = char.UpperTorso
        bp.Position = char.UpperTorso.Position
        bp.P = 10000
        bp.D = 1250
        bp.MaxForce = Vector3.new(4000,4000,4000)
       local bg = Instance.new("BodyGyro")
     bg.Parent = UpperTorso
   bg.D = 500
bg.MaxTorque = Vector3.new(char.UpperTorso.Position,Mouse.hit.p)
bg.P = 9999999
bg.CFrame = CFrame.new(char.UpperTorso.Position, Mouse.Hit.p)
char.Humanoid.AutoRotate = false
            wait()
bg:Destroy()
bp:Destroy()
char.Humanoid.AutoRotate = true
        end

    end
end)
UIS.InputEnded:Connect(function(inputObject)
    if(inputObject.KeyCode==Enum.KeyCode.U)then
        holdingUKey = false
    end
end)

5 comments

1

"They are redundant and its only use is in math." - this is not true. Please stop perpetuating this myth.

0

I still don't understand how i can fix my script. To work the proper way.

0

LookVector isn’t a property of humanoids. Second, and I could definitely be wrong, but I don’t think that is actually detecting that you’re holding the key down. It sees that input BEGAN, but not CONTINUED.

0

Actually @Karasu_H, the variable 'holdingUKey' is set to true until the InputEnded event was fired. So it stays true until he lets go of the key he was holding.

0

It sounds like you want to set the CFrame of the BodyGyro and not the MaxTorque, which represents magnitude and not direction

1 answer

Judging by just the title, you want:

bg.MaxTorque = Vector3.new(LookVector.X, LookVector.Y, LookVector.Z)

Make sure you change the LookVector to the humanoid.LookVector

hope this helped?

This discussion is preserved as it was. New answers, comments, and votes are closed.