Gyro taking long to start working

Ive been trying to make a script that makes a part rotate to the players mouse.Hit. It works fine but it takes too long to actually start rotating, there is a bodyvelocity in this part and it is unanchored (dont know if thats whats causing it or not)

Script:

local plr = game:GetService("Players").LocalPlayer
local Mouse = plr:GetMouse()

local Gyro = Instance.new("BodyGyro")
Gyro.Parent = workspace:WaitForChild("Part")
Gyro.D = 100
Gyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
Gyro.P = 1000

game:GetService("RunService").Heartbeat:Connect(function()
	Gyro.CFrame = Mouse.Hit
end)

Video:

Is there a way to make the gyro start its rotation instantly?

1 Like

Is there something that holds it back, like a wait() or something that’s loading

No, thats the entire script (30)

1 Like

It’s most likely that studio is rounding up before starting something, I’m not sure tho

Ive figured out that changing the parts CFrame instead of using a gyro makes it work instantly, but is there any way to make a CFrame replicate to the server?

New Code:

local plr = game:GetService("Players").LocalPlayer
local Mouse = plr:GetMouse()

local part = workspace:WaitForChild("Part")

game:GetService("RunService").Heartbeat:Connect(function()
	part.CFrame = CFrame.new(part.Position, part.Position + Mouse.Hit.LookVector)
end)

I suspect this is probably because of replication.

There are two things you can do:

  • If you want the part to move only on the client, create the part on the client.
  • if you want the part to move on the server and other clients and you want to move it from a LocalScript, use network ownership. On the server, set the network ownership to the player you’d like to control it.

If you already use network ownership, the delay could be from the change in ownership replicating.


Network ownership allows the client to control a part/assembly. Normally if the client tries to set the part’s position the part gets set back to where the server had it. If you give network ownership to a player, their client gets to control it (characters use ownership like this).


Edit:

Oh! Network ownership is how you do this. It’s why you can set the character’s CFrame on the client.

2 Likes

Change your BodyGyro | Roblox Creator Documentation and BodyGyro | Roblox Creator Documentation values.

Should be easy-peasy.

This is exactly what ive been looking for thanks!