For some reason, it won’t go past the first function. I can’t get the “input” warning.
ClickDetector.MouseHoverEnter:Connect(function()
warn("Hover")
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
warn("Input")
end
end)
end)
Is this in a LocalScript?
I’d also recommend taking your InputBegan
event and placing it outside of your MouseHoverEnter
event block.
1 Like
I’m confused what exactly you’re trying to do here, capture a key input while a click detector is focused?
Its worth noting that your code has a memory leak in it since you’re creating a new input handler every time the button is hovered
2 Likes
It’s a normal script, not local. The reason I’m putting the InputBegan event inside the MouseHoverEnter event is because- I’m doing a pick up object system. I have to check if the player has their mouse on the object, then check if they’ve pressed “e” to actually pick up the object.
UserInputService does not work in server scripts (how is it supposed to know who to listen to)
I would recommend using a local script, retrieving the player’s mouse object (through Player:GetMouse) and then handling your input where it checks if Mouse.Target is a valid part
If you want it networked, you’ll have to use a remote
1 Like
I don’t really understand what a memory leak is. lol
You have any ways to fix it?
You’re creating a new event binding every single time a client hovers the button.
This means a new chunk of memory is taken up by a connection object that is never cleaned up, over time, this will consume more and more of the server memory and it will never be released
1 Like
Alright, I can try that. I’m now realizing why it won’t listen for someone pressing “e”
Ah, I see. I will try to make it not have a memory leak. Is there any way you know to listen for hovering without a memory leak?