Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't the door open (Trying a new method)?

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)

8 comments

0

Any output? Are the doors anchored [they shouldn't be]. Please be more specific on the issue

0

I have the doors working on every other function that I put them on except this one. They are not anchored. No output

0

Question, are you sure it's still Door2?

0

By the way, your banned on roblox... So why are you on this site asking for scripting help... e.e

0

I'm sure it is. I'm still here because I'm on an alternate :P

1

KeyDown event is an Event directed from the Mouse. and the Mouse can only be accessed from a localscript.

0

Oh ok :)

1

I just made an answer to explain it better to you(:

1 answer

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.

1 comment

0

Thanks! It's just a 1 player server :)

This discussion is preserved as it was. New answers, comments, and votes are closed.