You can create the connection variable outside of the function.
And instead of creating the BodyGyro every time the function runs (will work only when active is true), check if the humanoid root part has it (when active is false), because then you create a disabled BodyGyro, instead of disabling the current one.
local LockModule = {}
local conn
function LockModule.Lock(active, plr)
local mouse = plr:GetMouse()
local Character = plr.Character or plr.CharacterAdded
local hum = Character:WaitForChild("Humanoid")
local rotation = Instance.new("BodyGyro")
rotation.P = 1000000
rotation.Parent = hum.RootPart
local User = game:GetService("UserInputService")
if active then
hum.CameraOffset = Vector3.new(1,0.5,0)
rotation.MaxTorque = Vector3.new(0, math.huge, 0)
conn = game:GetService("RunService").RenderStepped:Connect(function()
rotation.CFrame = mouse.Origin
User.MouseBehavior = Enum.MouseBehavior.LockCenter
end)
else
hum.CameraOffset = Vector3.new(0,0,0)
rotation.MaxTorque = Vector3.new(0, 0, 0)
if conn then conn:Disconnect() end
User.MouseBehavior = Enum.MouseBehavior.Default
end
end
return LockModule
Aight i finished the code now it works in a module, but would i module be better to use?
In case anybody was wondering, the weird rotation bug mentioned earlier in the topic is due to the BodyGyro’s rotation force conflicting with the character’s auto rotation. It’s noticeable when walking backwards because the character is trying to spin around to face the movement direction.
Simple fix: set Humanoid.AutoRotate to the necessary bool value when activating or deactivating the force shift-lock.
So your Using BodyGyro for Rotating the Body?? and also i’ve seen many People including me Back then Grabbing stuff, other People made, for my game including client sided Anti cheats (which u should never use)! And flying was always detected through BodyGyro.
So heres my Question could this be a Fly exploit Detection???
yeah sorry mind helping me? the rotation isn’t smooth at all and kinda like delayed? or simply it takes a bit to rotate, even with alot of 0 in the gyro.p https://gyazo.com/fc569400810bdfa20576b278dfa7018c