Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

6 comments

0

Errors please

0

Line 07: Does keycode.keycode not throw any errors?

0

no errors are displayed in the script

0

is this script a local script or server script?

0

capitalize the second "KeyCode"

0

It's in a Script.

1 answer

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

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