Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why won't the door open?

Asked by
cboyce1 40
10 years ago

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!

01function onKeyDown(key)
02    key = key:lower()
03    if key == "e" then
04    t.BodyVelocity.velocity = Vector3.new(3, 0, 0)
05    wait (3)
06    t.BodyVelocity.velocity = Vector3.new(-3, 0, 0)
07    end
08end
09 
10t.KeyDown:connect(onKeyDown)

(Is this right?)

2
You never connected the function to an event, silly. Add a connection line(: Goulstem 8144 — 10y
1
Oh haha XD right. Simple solution. Thanks :) cboyce1 40 — 10y
0
Can you just double check that I've got the connection line right please? cboyce1 40 — 10y
0
You never defined 't' Goulstem 8144 — 10y
0
This is part of a script. Earlier on I did define 't' cboyce1 40 — 10y

1 answer

Log in to vote
0
Answered by
yoshiegg6 176
10 years ago

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.

01DoorRange = game.Workspace.DoorRange --A brick near your door that allows you to open it if you're inside of it.
02CAS = game:GetService("ContextActionService")
03 
04 
05function onKeyDown(key)
06    t.BodyVelocity.velocity = Vector3.new(3, 0, 0)
07    wait (3)
08    t.BodyVelocity.velocity = Vector3.new(-3, 0, 0)
09    end
10end
11 
12DoorRange.Touched:connect(function(part)
13if part and part.Parent == player.Character then
14CAS:BindActionToInputTypes("CASNameHere", onKeyDown, true, "e")
15end
View all 22 lines...
Ad

Answer this question