I want to make something happen when the player presses a key when they are not typing in chat. Problem is that shift is the only key can’t be false in gameProcessedEvent for some reason. Why is this happening and how do I know if the player is typing in chat when they press shift?
Use gameProcessedEvent parameter for detecting if they are typing in chat or have clicked off the window.
Since that won’t work for you, I recommend using ContextActionService
.
you need to disable this option in starter player EnableMouseLockOption
in order to use shift normally in any localscript
You can do this too, but ContextActionService might have the possibility to override shiftlock.
ye but ContextActionService
will shiftlock and trigger the callback at the same time
wait what would this do? would I still be able to shiftlock?
No, you would not. It would be beneficial if you wasn’t able to since, you’d be using the shift button to run anyway.
wait but could I shiftlock if I had shiftlock bound to a different key tho?
Roblox’s default shiftlock possibly isn’t able to be bounded to anything else than it’s default. You could see if it’s possible with a search, if it is I’m believing it’s probably altering roblox’s CoreGui code.
no like I made shiftlock bound to control in my game and I want to know if I use the suggestion from above to fix my problem I can still shiftlock using the control key
Yeah you probably can. I’m not too sure though, if it doesn’t work, let us know.
well how would I go about doing this? the comment above is kinda vague
Is this the one you’re specifically talking about?
no uh this one
you need to disable this option in starter player
EnableMouseLockOption
in order to use shift normally in any localscript
If you know where StarterPlayer is… you’ll need to click on that, then find the property EnableMouseLockOption
and I believe tick it off.
oh lol I didnt realize it had properties. so i can’t shiftlock even with my shiftlock on control and it hasn’t really fixed my problem. the shift key is still being counted as true for gameProcessedEvent even when Im not in chat
You mind sharing the portion of the code that’s controlling the shift key?
running script
local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild('Humanoid')
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://10198983764'
RAnimation = Humanoid:LoadAnimation(RunAnimation)
_G.RunningSpeed = 32
Running = false
function Handler(BindName, InputState)
if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then
Running = true
RunningVar = _G.RunningSpeed
Humanoid.WalkSpeed = RunningVar
elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then
Running = false
if RAnimation.IsPlaying then
RAnimation:Stop()
end
Humanoid.WalkSpeed = 16
end
end
Humanoid.Running:connect(function(Speed)
if Speed >= 10 and Running and not RAnimation.IsPlaying then
RAnimation:Play()
RunningVar = _G.RunningSpeed
Humanoid.WalkSpeed = RunningVar
elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
RAnimation:Stop()
Humanoid.WalkSpeed = 16
elseif Speed < 10 and RAnimation.IsPlaying then
RAnimation:Stop()
Humanoid.WalkSpeed = 16
end
end)
Humanoid.StateChanged:connect(function(old, new)
if new == Enum.HumanoidStateType.Jumping and RAnimation.IsPlaying then
RAnimation:Stop()
end
end)
game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)
One thing I’d like to point out is the _G.RunningSpeed is exploitable. _G is making it a global variable. Not only is it just terrible for performance, but exploiters can modify the variable with a quick code; making it any variable they want.
But it seems like the code you sent works… I don’t know what’s the real problem here.
Here’s just some modifications I’ve made to it:
local ContextActionService = game:GetService("ContextActionService")
local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
local RunAnimation = Instance.new("Animation")
RunAnimation.AnimationId = "rbxassetid://7377917726"
RAnimation = Humanoid:LoadAnimation(RunAnimation)
local RunningSpeed = 32
local Running = false
function Handler(BindName, InputState)
if InputState == Enum.UserInputState.Begin and BindName == "RunBind" then
Running = true
Humanoid.WalkSpeed = RunningSpeed
elseif InputState == Enum.UserInputState.End and BindName == "RunBind" then
Running = false
if RAnimation.IsPlaying then
RAnimation:Stop()
end
Humanoid.WalkSpeed = 16
end
end
Humanoid.Running:Connect(function(Speed)
if Speed >= 10 and Running and not RAnimation.IsPlaying then
RAnimation:Play()
Humanoid.WalkSpeed = RunningSpeed
elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
RAnimation:Stop()
Humanoid.WalkSpeed = 16
elseif Speed < 10 and RAnimation.IsPlaying then
RAnimation:Stop()
Humanoid.WalkSpeed = 16
end
end)
Humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Jumping and RAnimation.IsPlaying then
RAnimation:Stop()
end
end)
ContextActionService:BindAction("RunBind", Handler, true, Enum.KeyCode.LeftShift)
you can shiftlock if you copy PlayersModules
you can find it in your localPlayer.PlayerScripts
and Copy it and Past it into StarterPlayer.StarterPlayerScript
go To PlayerModule.CameraModule.MouseLockController
opent the module and go to line 31 you will find :
self.boundKeys = {Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift} -- defaults
Now Change to what ever you like
then you will find String value under MouseLockController
make sure you change the value to what ever you set as default shiftlock key
and you can now shiftlock with any key you want and use shift to what ever you want
i hope that was helpfull