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

Rotating a part to face mouse, With body gyro?

I'm trying to make a part's rotation face the player's mouse when the player holds down "w", and only on the Y rotation. It doesn't work, the output prints w is down, and the loop worked over and over again untill I stop pressing "w" , so those 2 work, but the part still doesn't rotation on Y to face the part!1 And it isn't because the "script.Parent.GetMousePosition.MousePosition.Value" isn't working, I put a print in that script too, and it DOES work.. Hellllp mee?

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Car = game.Workspace:FindFirstChild(""..Plr.Name.."'s_Car")
local Speed = 5000000
local WIsDown = script.Parent.WScript.WIsDown


WIsDown.Changed:connect(function(Value)
	if Value == true then
		print("w is down")
		local Force = Instance.new("BodyGyro")
		Force.maxTorque = Vector3.new(0,Speed,0)
		Force.D = 10000
		Force.P = 10000
		Force.Name = "TurnForce"
		repeat
			print("the loop worked")
			wait(0.05)
			Force.cframe = script.Parent.GetMousePosition.MousePosition.Value
		until WIsDown.Value == false
		Force:Destroy()
	end
end)

1 answer

✓ Accepted answer

You don't need body gyro. You can use a special feature with CFrame that allows you to input 2 vectors as 1st and second arguments, and returns a nice CFrame that points to it's second argument.

Like this:

p.CFrame = CFrame.new(OriginalPosition, PointToPosition)

So, here could be your script:

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Car = game.Workspace:FindFirstChild(""..Plr.Name.."'s_Car")
local Speed = 5000000
local WIsDown = script.Parent.WScript.WIsDown

local Part = nil -- assuming a part's value is here


WIsDown.Changed:connect(function(Value)
    if Value == true then
        print("w is down")
        repeat
            wait(0.05)
            Part.CFrame = CFrame.new(Part.Position, Mouse.Hit.p)
        until WIsDown.Value == false
    end
end)

If you want more help on how to use this stuff, PM me.

4 comments

0

I'm usinf body gyro because this part is in a model, I need body gyro for what I'm making.

0

Using*

0

Omg I know what I did wrong now, I didn't give the force a parent lol, ty I would of not realized that without reading your code xd

0

Yw, lol.

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