What do you want to achieve? I am creating a movement delay (for stopping). When W is no longer being held, it should take the character 1.5 seconds to stop instead of stopping immediately. I haven’t fully finished the system, but I have run into an issue while using ContextActionService.
What is the issue? 1, 2, and 3 prints. Test, works1, and works2 do NOT print. My event “UserInputService.InputEnded:Connect” doesn’t seem to be running. The code doesn’t get stuck, as it prints 1, 2, and 3.
This is a server script in ServerScriptService. There are no other scripts or local scripts that could be tampering with this. Thanks!
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local actionSlipping = "slipping"
local function slippingFunctionAction(actionName, inputState, _inputObject)
if actionName == actionSlipping and inputState == Enum.UserInputState.End then
print('test')
end
end
print('1')
UserInputService.InputEnded:Connect(function(input)
print('works1')
if input.KeyCode == Enum.KeyCode.W then
print("works2")
ContextActionService:BindAction(actionSlipping, slippingFunctionAction, true, Enum.KeyCode.W)
end
end)
print('2')
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
ContextActionService:UnbindAction(slippingFunctionAction)
end
end
end)
print('3')
You’re trying to use UserInputService in a server script. UserInputService is a client-side service and can only be used in LocalScripts or ModuleScripts required by LocalScripts. This is why your UserInputService.InputEnded:Connect and UserInputService.InputBegan:Connect events are not firing
To fix this you should move your code to a LocalScript. If you need to communicate with the server, you can use RemoteEvents or RemoteFunctions.
Thank you! Most is now printing… except for the CAS.
‘test’ is the only thing that will NOT print. The script knows I stopped holding W, but won’t run the function slippingFunctionAction I made using context action service. Why?
As for the ContextActionService not printing ‘test’, it’s because you’re unbinding the action in the UserInputService.InputBegan:Connect function not 100% sure tho. When you press the W key, it unbinds the action before it will get a chance to end. Try moving the unbinding of the action to the UserInputService.InputEnded:Connect function after the binding of the action.