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.
DoorRange = game.Workspace.DoorRange
CAS = game:GetService("ContextActionService")
function onKeyDown(key)
t.BodyVelocity.velocity = Vector3.new(3, 0, 0)
wait (3)
t.BodyVelocity.velocity = Vector3.new(-3, 0, 0)
end
end
DoorRange.Touched:connect(function(part)
if part and part.Parent == player.Character then
CAS:BindActionToInputTypes("CASNameHere", onKeyDown, true, "e")
end
end)
DoorRange.TouchEnded:connect(function(part)
if part and part.Parent == player.Character then
CAS:UnbindAction("CASNameHere")
end
end)
5 comments
You never connected the function to an event, silly. Add a connection line(:
Oh haha XD right. Simple solution. Thanks :)
Can you just double check that I've got the connection line right please?
You never defined 't'
This is part of a script. Earlier on I did define 't'