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

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

Asked by
cboyce1 40
9 years ago

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)
0
Any output? Are the doors anchored [they shouldn't be]. Please be more specific on the issue DigitalVeer 1473 — 9y
0
I have the doors working on every other function that I put them on except this one. They are not anchored. No output cboyce1 40 — 9y
0
Question, are you sure it's still Door2? EmergencyAlt2 50 — 9y
0
By the way, your banned on roblox... So why are you on this site asking for scripting help... e.e EmergencyAlt2 50 — 9y
View all comments (4 more)
0
I'm sure it is. I'm still here because I'm on an alternate :P cboyce1 40 — 9y
1
KeyDown event is an Event directed from the Mouse. and the Mouse can only be accessed from a localscript. Goulstem 8144 — 9y
0
Oh ok :) cboyce1 40 — 9y
1
I just made an answer to explain it better to you(: Goulstem 8144 — 9y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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.

0
Thanks! It's just a 1 player server :) cboyce1 40 — 9y
Ad

Answer this question