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

Why doesn't my door open when I press "E"?

Asked by 3 years ago

Hi, why doesn't my door open?

local db = false
local open = script.Parent.Open
local ind = script.Parent.Tuer

script.Parent.CardScanner.Scanner.Touched:Connect(function(p)
    if db == false then
        db = true
        if p.Parent:FindFirstChild("12345") ~= nil then
            if open.Value == false then
                local f = script.Parent.Tuer.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
                for i = 0,1,0.1 do
                    local cfm = script.Parent.Tuer.PrimaryPart.CFrame:Lerp(f,i)
                    script.Parent.Tuer:SetPrimaryPartCFrame(cfm)
                    wait()
                end
                open.Value = true
                wait(1.5) --- How long the door will stay open
                local f2 = script.Parent.Tuer.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
                for i = 0,1,0.1 do
                    local cfm = script.Parent.Tuer.PrimaryPart.CFrame:Lerp(f2,i)
                    script.Parent.Tuer:SetPrimaryPartCFrame(cfm)
                    wait()
                end
                open.Value = false
            end
        else
            print("Keycard wurde nicht akzeptiert oder erkannt")
            script.Parent.CardScanner.RingLight.BrickColor = BrickColor.new("Really red")
            wait(1.5)
            script.Parent.CardScanner.RingLight.BrickColor = BrickColor.new("Parsley green")
        end
        db = false
    end
end)

This script with the keycard reader is working. But this script with the 'Press E to interact' won't work.?

local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Tuer = script.Parent.Tuer
local open = script.Parent.Open

UIS.InputBegan:Connect(function(keycode)
    if keycode.keycode == Enum.KeyCode.E then

    if(Door.Position - HumanoidRootPart.Position).magnitude < 15 then
    wait()
    if open.Value == false then
                local f = script.Parent.Tuer.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
                for i = 0,1,0.1 do
                    local cfm = script.Parent.Tuer.PrimaryPart.CFrame:Lerp(f,i)
                    script.Parent.Tuer:SetPrimaryPartCFrame(cfm)
                    wait()
                end
                open.Value = true
                wait(1.5) --- How long the door will stay open
                local f2 = script.Parent.Tuer.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
                for i = 0,1,0.1 do
                    local cfm = script.Parent.Tuer.PrimaryPart.CFrame:Lerp(f2,i)
                    script.Parent.Tuer:SetPrimaryPartCFrame(cfm)
                    wait()
                end
                open.Value = false
            end
        else
        end
    end
end)

"Tuer" means "Tür", i.e. door [--- It's german Can you help me? The door should open when the player presses "E" within a radius of 15. Thanks for your help.

PinoRisi03

0
Errors please Feroxidus 83 — 3y
0
Line 07: Does keycode.keycode not throw any errors? ConsteIeo 63 — 3y
0
no errors are displayed in the script PinoRisi03 -3 — 3y
0
is this script a local script or server script? TrippeDanieI 21 — 3y
View all comments (2 more)
0
capitalize the second "KeyCode" Flasker917 21 — 3y
0
It's in a Script. PinoRisi03 -3 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

So..., I've tried the script on another world. An error is displayed in the output:

Workspace.Zauntore.Tor.Script:1: attempt to index nil with 'Character'  -  Server  -  Script:1
  Stack Begin  -  Studio
  Script 'Workspace.Zauntore.Tor.Script', Line 1  -  Studio  -  Script:1
  Stack End  -  Studio

I once wrote it in a LUA box because otherwise the paragraphs would obscure I hope this can help you find the problem. :)

Thank you

Ad

Answer this question