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?

I'm asking the door to open for me, and it won't, and I have no clue why.

Could somebody please change the script so that it's either more efficient or actually works?

Thanks!

function onKeyDown(key)
	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

t.KeyDown:connect(onKeyDown)

(Is this right?)

5 comments

2

You never connected the function to an event, silly. Add a connection line(:

1

Oh haha XD right. Simple solution. Thanks :)

0

Can you just double check that I've got the connection line right please?

0

You never defined 't'

0

This is part of a script. Earlier on I did define 't'

1 answer

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 --A brick near your door that allows you to open it if you're inside of it.
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)

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