Did you define mouse? It seems like t and your mouse are the same, but it aslo seems like t is the door. Could you show the t varible? Second, instead of using key:lower() you can just use if key == "e" or "E". Lastly, you can use context action service so that you can only open the door when you've touched a brick that's near it.
Here's a more efficient script of this using the link above. To use this make a part thats in front of you door. Make it invisible and non collideable but anchored. Name it DoorRange. Resize it however you like.
01 | DoorRange = game.Workspace.DoorRange |
02 | CAS = game:GetService( "ContextActionService" ) |
05 | function onKeyDown(key) |
06 | t.BodyVelocity.velocity = Vector 3. new( 3 , 0 , 0 ) |
08 | t.BodyVelocity.velocity = Vector 3. new(- 3 , 0 , 0 ) |
12 | DoorRange.Touched:connect( function (part) |
13 | if part and part.Parent = = player.Character then |
14 | CAS:BindActionToInputTypes( "CASNameHere" , onKeyDown, true , "e" ) |
18 | DoorRange.TouchEnded:connect( function (part) |
19 | if part and part.Parent = = player.Character then |
20 | CAS:UnbindAction( "CASNameHere" ) |