So basically, I am using ContextActionService to bind a function, but I want it to do something WHEN I press it and something else WHEN I let the key go.
Sadly it seems buggy:
local Cooldown = Moves[actionName].Frame:WaitForChild("Cooldown")
Cooldown.Size = UDim2.new(1, 0, 1, 0)
local Amount = #Connection + 1
Connection[Amount] = Services.UserInputService.InputEnded:Connect(function(Input)
if Input == inputObject then
Services.TweenService:Create(Cooldown, TweenInfo.new(1), {Size = UDim2.new(1, 0, 0, 0)}):Play()
Connection[Amount]:Disconnect()
Connection[Amount] = nil
end
end)
The reason this is happening is most likely due to bad indexing. You can do something a little simpler, I would assume. I would also like to ask why you are storing all of your connections in a table?
local ContextActionService = game:GetService("ContextActionService")
local ACTION_NAME = "OpenDoor" -- Change this to something unique that makes sense
local INPUTS = { Enum.KeyCode.E } -- Add other KeyCode you see fit here
local function handleAction(actionName, inputState, inputObject)
if actionName == ACTION_NAME then
if inputState == Enum.UserInputState.Begin then
-- The key is pressed, mouse button down, etc...
elseif inputState == Enum.UserInputState.End then
-- The key is released, mouse button released, etc...
end
end
end
-- When the action becomes relevant:
ContextActionService:BindAction(ACTION_NAME, handleAction, false, unpack(INPUTS))
-- When the action is no longer relevant:
ContextActionService:UnbindAction(ACTION_NAME)
To answer your question, InputObject.UserInputState is the property you want to check, much like in my example above.
@OminousVibes0 When UserInputService you can type a variable…
local uis = game:GetService(“UserImputService”)
then you can connect the key maybe for example your Key Is M
Type this script under the variable
function onKeyPress(action, UserInputState, inputobject)
if userInputState == Enum.UserInputSate.Begin then
– type in here what you want the script to do if you want it to something in the output type
print(“M Was Pressed”)
–after type what you want the script to do type this in your script
end
end
game.ConextActionService:BindAction(“keyPressSpecialName”, onKeyPress, true,Enum.KeyCode.M)
– What You Want Your Keycode to be
game.ConextActionServiceSetPostion:BindAction(“keyPressSpecialName”, UDim2.new(0.01,0,.6,0)
– This line sets the position of it to near the jump button
game.ConextActionService:SetImage(“keyPressSpecialName”, " – Paste the image link here")
If you dont understand what i said watch this video