What should I add so that when MouseButton1 is not being held anymore for 5 seconds shiftlock will turn off?

What should I add so that when MouseButton1 is not being held anymore for 5 seconds shiftlock will turn off?


Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		_G.ForceShiftLock = true	
	end)
end)

One question, why are you using _G variables lol.
Second I’d just do; (I’m on mobile so sorry if the code is horrible.

Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
— Assuming it’s already false
If _G.ForceShiftLock == false then
_G.ForceShiftLock = true
else
_G.ForceShiftLock = false
end
— This is so it can be triggered for however long the player wants it to be.
end)
end)

Try to avoid using _G, you can use module scripts instead.

You can try this:

local userInput = game:GetService("UserInputService")

userInput.InputBegan:Connect(function(input)
	local inputType = input.userInputType

	if inputType == Enum.UserInputType.MouseButton1 then -- As long as mouse button 1 is being held it wont turn off
		_G.ForceShiftLock = true
	end
end)

userInput.InputEnded:Connect(function(input)
	local inputType = input.userInputType
	
	if inputType == Enum.UserInputType.MouseButton1 then -- If user stopped holding mouse button 1, then wait 5 seconds and turn shift lock off
		wait(5)
		_G.ForceShiftLock = false
	end
end)

Thank you to both! Appreciate it guys! Also I’m not sure why I used G variables haha, I’m gonna change it.