i tried different solutions but all just had the same result of this basic script:
01 | local frame = script.Parent.EmoteFrame |
02 |
03 | local player = game.Players.LocalPlayer |
04 | local mouse = player:GetMouse() |
05 |
06 | mouse.KeyDown:connect( function (key) |
07 | if key:lower() = = "e" or key:upper() = = "E" then |
08 | frame:TweenPosition(UDim 2. new( 0.5 , 0 , 0.059 , 0 ), "Out" , "Quad" , 0.2 , true ) |
09 | else |
10 | frame:TweenPosition(UDim 2. new( 0.5 , 0 ,- 0.15 , 0 ), "Out" , "Quad" , 0.2 , true ) |
11 | end |
12 | end ) |
Try using UserInputService.
https://developer.roblox.com/en-us/api-reference/class/UserInputService
You can do something like this.
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 |
03 | UserInputService.InputBegan:Connect( function (input, gameProcessed) |
04 | if gameProcessed then return end |
05 | if input.KeyCode = = Enum.KeyCode.E then |
06 | --Code |
07 | end |
08 | end ) |
09 |
10 | UserInputService.InputEnded:Connect( function (input, gameProcessed) |
11 | if gameProcessed then return end |
12 | if input.KeyCode = = Enum.KeyCode.E then |
13 | --Code |
14 | end |
15 | end ) |
You have to use UserInputService
and its ImputBegan
and InputEnded
events. Mouse.KeyDown
is deprecated.
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 |
03 | local frame = script.Parent.EmoteFrame |
04 | frame.Visible = false |
05 |
06 | local player = game.Players.LocalPlayer |
07 |
08 | UserInputService.InputBegan:Connect( function (input, gameProcessedEvent) |
09 | if input.KeyCode = = Enum.KeyCode.E and not gameProcessedEvent then |
10 | frame.Position = UDim 2. new( 0.5 , 0 , 0.059 , 0 ) |
11 | frame.Visible = true |
12 | end |
13 | end ) |
14 |
15 | UserInputService.InputEnded:Connect( function (input, gameProcessedEvent) |
16 | if input.KeyCode = = Enum.KeyCode.E and not gameProcessedEvent then |
17 | frame.Visible = false |
18 | end |
19 | end ) |
The InputBegan
event fires when a client makes an input (keyboard keys, mouseButton, etc.) Then there's an if statement checking if the key is "E" and the player isn't in chat. Finally, it makes the frame visible.
The InputEnded
event fires when a client ends an input (keyboard keys, mouseButton, etc.) Then there's an if statement checking if the key is "E" and the player isn't in chat. Finally, it makes the frame invisible.