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)
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.