hi, so I’m using the OTS module script from somewhere I got, kinda forgot where but I want to make it so if the player shifts then it enables, and shifts again it disables.
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local render = game:GetService("RunService")
render.Heartbeat:Connect(function()
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
local module = require(script:WaitForChild("ShoulderCamera"))
module:Enable()
end
end)
I can only seem to make it work with enabling and not disabling…
local module = require(script:WaitForChild("ShoulderCamera"))
render.Heartbeat:Connect(function()
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
module:Enable()
else
module:Disable()
end
end)
Have you already tried that? I believe the problem is that you are requiring it inside of the if statement so the else statement is unable to get the variable “module”
Yep, but it won’t work. The module detects if it’s already disabled but is still also tried being disabled. that’s why it prints something like “The module is already disabled!” and it spams the thing cuz of heartbeat
I see what you mean, well you can add in a bool value that you change depending on if it’s enabled or disabled so you don’t disable it when it’s not enabled.
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local render = game:GetService("RunService")
local module = require(script:WaitForChild("ShoulderCamera"))
local shifted = script.Parent.Shiftlocking.Value
UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.LeftShift then
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter and shifted == false then
shifted = true
module:Enable()
elseif not UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter and shifted == true then
shifted = false
module:Disable()
end
end
end)
It doesn’t enable the module when I shift lock but when I do this: Shift lock > Unshiftlock > Shift lock, it works and enables the module
With some camera cframing you could probably just remake what the module does, and since it’s made by you you’ll know how to enable/disable it correctly.
But if you don’t want to do that you can always add your own adjustments to the module and figure out how they did it so you can change it to your liking.
I never said I made the module… I provided the modulescript’s original thread in a previous reply here, please carefully look at the post properly next time.
I never said you did, please read my message properly next time.
Regardless all you have to do is figure out how to adjust the module to your liking so you can disable / enable it the way you want to. I never said it was yours, I said if you remade it from scratch then it would be yours and you can change it up the way you want to.
local UIS = game:GetService("UserInputService")
local module = require(script:WaitForChild("ModuleScript"))
UIS:GetPropertyChangedSignal("MouseBehavior"):Connect(function()
if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter then
module:Enable()
else
module:Disable()
end
end)
I wouldn’t advise using any loop for this be it a while true do or heartbeat/stepped since you can just setup an event listener which listens for the value of the property to change.
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local render = game:GetService("RunService")
local module = require(script:WaitForChild("ShoulderCamera"))
local shifted = script.Parent.Shiftlocking.Value
local connection = nil
UIS.InputBegan:Connect(function(input, processed)
if processed then
return
end
if input.KeyCode == Enum.KeyCode.LeftShift then
connection = UIS:GetPropertyChangedSignal("MouseBehavior"):Connect(function()
if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter and not shifted then
shifted = true
module:Enable()
elseif not UIS.MouseBehavior == Enum.MouseBehavior.LockCenter and shifted then
shifted = false
module:Disable()
end
end)
end
end)
UIS.InputEnded:Connect(function(input, processed)
if processed then
return
end
if input.KeyCode == Enum.KeyCode.LeftShift then
if connection then
connection:Disconnect()
end
end
end)
Previous concept applied to your script & a way for the connection to be disconnect (to prevent potential memory leaks).