This is a new method from the last script. It still won't work. How can I fix it?
Thanks :)
t = script.Parent.Parent.Door2 function onKeyDown(key) if (key~=nil) then key = key:lower() if (key=="e") then t.BodyVelocity.velocity = Vector3.new(3, 0, 0) wait (3) t.BodyVelocity.velocity = Vector3.new(-3, 0, 0) end end end t.KeyDown:connect(onKeyDown)
Your problem is that you're trying to use the KeyDown
event on an Instance, when it is an event of the mouse.
To fix this, first start by putting this in a LocalScript, because the mouse
can only be accessed from a localscript.
Now you should get the player using the LocalPlayer. Then get their mouse, then use the KeyDown event on it.. and finally move the part.
local t = script.Parent.Parent.Door2 local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local keyy = 'e' --key to press mouse.KeyDown:connect(function(key) if key:lower() == keyy:lower() then --check the key t.BodyVelocity.velocity = Vector3.new(3, 0, 0) wait (3) t.BodyVelocity.velocity = Vector3.new(-3, 0, 0) end end
I suggest you also look into using a global Debounce, with a boolvalue. For multiple player servers.
This should be a LocalScript in somewhere client-sided e.g. StarterGui, StarterPack.