Hello
so i have a weird problem and for some reason if i start sprinting and press keybind 2 i stop and unlock the mouse with and without tool:
As you see here evertihing else works fine and even without tools pressing keybind 2 would unlock my mouse and stop me Note it only happens when im sprinting so
sprintscript:
local Cas = game:GetService("ContextActionService")
local RNS = game:GetService("RunService")
local SprintData = require(script.Parent:WaitForChild("CharacterStats")) -- Your module script here
local staminausage = 0.2
local stamianrecharg = 0.25
local rechargeTime = 0.25
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local RootPart = char:WaitForChild("HumanoidRootPart")
local RunSound = RootPart:WaitForChild("Running")
local sprint = script.RunAnim
local Runanim = humanoid.Animator:LoadAnimation(sprint)
local lastSprint = math.huge
local isSprinting = false
humanoid.JumpPower = 40
local jumpCooldown = 1
local canJump = true
humanoid.StateChanged:Connect(function(_, newstate)
if newstate == Enum.HumanoidStateType.Jumping and canJump then
isSprinting = false
Runanim:Stop()
humanoid.WalkSpeed = SprintData.BaseWalkSpeed * SprintData.SpeedIncreaseDecrease
RunSound.PlaybackSpeed = 1
canJump = false
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
task.delay(jumpCooldown, function()
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
canJump = true
end)
end
end)
local function sprint(actionname, inputstate, inputtyp)
if inputstate == Enum.UserInputState.Begin then
isSprinting = true
elseif inputstate == Enum.UserInputState.End then
isSprinting = false
end
if isSprinting then
humanoid.WalkSpeed = SprintData.SprintSpeed * SprintData.SpeedIncreaseDecrease -- Using the module speed
RunSound.PlaybackSpeed = 1.25
if humanoid.MoveDirection.Magnitude > 0 then
Runanim:Play()
end
else
humanoid.WalkSpeed = SprintData.BaseWalkSpeed * SprintData.SpeedIncreaseDecrease
RunSound.PlaybackSpeed = 1
Runanim:Stop()
end
end
Cas:BindAction("Sprint", sprint, true, Enum.KeyCode.LeftShift)
RNS.Heartbeat:Connect(function(delta)
local stamina = SprintData.Stamina
if not isSprinting then
humanoid.WalkSpeed = SprintData.BaseWalkSpeed * SprintData.SpeedIncreaseDecrease
else
-- If sprinting, apply SprintSpeed with SpeedIncreaseDecrease
humanoid.WalkSpeed = SprintData.SprintSpeed * SprintData.SpeedIncreaseDecrease
end
if stamina < staminausage then
isSprinting = false
RunSound.PlaybackSpeed = 1
Runanim:Stop()
humanoid.WalkSpeed = SprintData.BaseWalkSpeed * SprintData.SpeedIncreaseDecrease
end
if isSprinting and humanoid.MoveDirection.Magnitude > 0 then
SprintData.Stamina = stamina - staminausage -- Reduce stamina using the module
lastSprint = tick()
else
if tick() - lastSprint >= rechargeTime and SprintData.Stamina < SprintData.MaxStamina then
SprintData.Stamina = SprintData.Stamina + stamianrecharg
end
end
end)
and my mouse unlock script
--Copy and paste into starter player scripts
local UIS = game:GetService("UserInputService")
--Camera module services
local cameraModule = script.Parent:WaitForChild("PlayerModule"):WaitForChild("CameraModule")
local CameraUtils = require(cameraModule:WaitForChild("CameraUtils"))
local BaseCamera = require(cameraModule:WaitForChild("BaseCamera"))
local CameraUI = require(cameraModule:WaitForChild("CameraUI"))
local CameraInput = require(cameraModule:WaitForChild("CameraInput"))
local CameraToggleStateController = require(cameraModule:WaitForChild("CameraToggleStateController"))
local UserGameSettings = UserSettings():GetService("UserGameSettings")
local MouseLocked = false
local mouseBehavior = Enum.MouseBehavior.LockCenter
local function MouseLock()--funtion that should lock the cursor
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end
MouseLock()
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end --exit function if they are typing
if input.KeyCode == Enum.KeyCode.C then
MouseLocked = not MouseLocked --turn mouselocked to true if false, false if true
if MouseLocked then --if true then lock mouse
mouseBehavior = Enum.MouseBehavior.LockCenter
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
else
mouseBehavior = Enum.MouseBehavior.Default
UIS.MouseBehavior = Enum.MouseBehavior.Default
end
end
end)
local debounce = false
function BaseCamera:UpdateMouseBehavior()
local blockToggleDueToClickToMove = UserGameSettings.ComputerMovementMode == Enum.ComputerMovementMode.ClickToMove
if self.isCameraToggle and blockToggleDueToClickToMove == false then
CameraUI.setCameraModeToastEnabled(true)
CameraInput.enableCameraToggleInput()
CameraToggleStateController(self.inFirstPerson)
else
CameraUI.setCameraModeToastEnabled(false)
CameraInput.disableCameraToggleInput()
-- first time transition to first person mode or mouse-locked third person
if self.inFirstPerson or self.inMouseLockedMode then
CameraUtils.setRotationTypeOverride(Enum.RotationType.CameraRelative)
if not debounce then
debounce = true
CameraUtils.setMouseBehaviorOverride(mouseBehavior)
end
else
debounce = false
CameraUtils.restoreRotationType()
CameraUtils.restoreMouseBehavior()
end
end
end
task.wait(2.5)
MouseLock()
as you can see none of these script ever mentions to press 2 but for some reson it does interfere is that a direct mechanic from roblox? and when yes how to remove it?
thank you