UserInputSerivce:IsKeyDown() not working properly

Hello, I would like to create a Door Interaction system.

The problem is, I want the Interaction Progress tween the size only if the player is pressing E all the time until tween ends, however, if I tap E one time, the tween goes all the way up anyways, I want also the Interaction Progress to go down if the E is not pressing.

Copy paste the script here, by the way you should use the parameters of InputBegan instead:
https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan
The parameter called Input is an InputObject, InputObjects have this Property called UserInputType you can use this to check if they are holding Enum.KeyCode.E down.

It still doesn’t work for some reason.

It’s because the function isn’t returning anything, in the function do if UserInputService:IsKeyDown(Enum.KeyCode.E) then return true

Or just do return UserInputService:IsKeyDown(Enum.KeyCode.E) for the sake of simplicity.

This could work too either works, I’m just used to doing that, besides he may want to return a string or something in the future.

Script looks like this and still doesn’t work.

and not IsKeyHold()
Remove not?

it should be

UserInputService.InputBegan:Connect(function()
   if NearGui ~= false and IsKeyHold() then
     -- tween
    else
     -- tween
    end
end)

Also this code in-general could be redone to be much better and more efficient for your needs

1 Like

Looks like this and Tween still goes all the way up even if I tap the E.

Try replacing the TweenSize with .Visible = true/false for now. if that didn’t change it, I think the size is bad. Also, always use scale! The correct one is this {0.067, 0},{-0.114, 0}.But still, try using .Visible and making sure that the position is right. When I used the size for a new textbutton, it was offscreen.

image

I don’t really think GUI is the problem here.

Just make sure it’s visible/enabled by default, I dont see you changing it anywhere here.
Also, add this code just to see.

RunService.Heartbeat:Connect(function()
print(NearGUI)
print(IsKeyHold)
end)

Tell me the result when you’re near the GUI and if you’re holding E

There is only true, false when you are near door.

I see the issue.

Delete KeyDown = true in the function.
And, at the start of the UIS.InputBegan function, put IsKeyHold().

What do you mean by at the start of UserIS?

UserInputService == UIS, just an easier thing than typing it.

So make it

UserInputService.InputBegan:Connect(function()
local KeyDown = IsKeyHold()
if NearGUI ~= false and KeyDown then
--//code
end
end)
1 Like

Changed still, even if I tap E it goes all the way up.