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
9 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!

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?)

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

1 answer

Log in to vote
0
Answered by
yoshiegg6 176
9 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.

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)

Ad

Answer this question