I have made a keycard door, but there is a problem. It only needs the player to have a keycard when opening the door once, and it lets the player open the door without a keycard after. Is there a way I can make it so every time the player needs a keycard to open the door? Event firing script: (localscript)
local runservice = game:GetService("RunService")
local desiredInterval = 0.65
local counter = 0
local holdingkey = false
local UIS = game:GetService("UserInputService")
local door = game.Workspace.ButtonDoor5
local PrimaryPart = door.PrimeDoor.PrimaryPart
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local char = player.Character
local root = char.HumanoidRootPart
local event = game.ReplicatedStorage.OpenKeyDoor
local NearDoor = false
runservice.Heartbeat:Connect(function(step)
counter = counter + step --step is time in seconds since the previous frame
if counter >= desiredInterval then
counter = counter - desiredInterval
if char:FindFirstChild("card") then
holdingkey = true
if holdingkey == true then
if (PrimaryPart.Position - root.Position).Magnitude <= 5 then
NearDoor = true
if (PrimaryPart.Position - root.Position).Magnitude >= 5 then
NearDoor = false
if mouse.Target == "PrimaryPart" then
PrimaryPart.EToOpen.Enabled = true
end
end
end
end
end
end
end)
UIS.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.Keyboard then
local Key = Input.KeyCode
if Key == Enum.KeyCode.E and holdingkey and NearDoor == true then
event:FireServer()
end
end
end)
Door Opening Script: (server Script inside door)
local Door1 = script.Parent.Door1
local Door2 = script.Parent.Door2
local player = game.Players.LocalPlayer
local neon = script.Parent.Button.Neon
local neonb = script.Parent.Button2.Neon2
local debounce = false
local opened = false -- new variable
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(0.8, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local DoorOpen1 = {CFrame = Door1.CFrame + Door1.CFrame.lookVector * -4}
local DoorOpen2 = {CFrame = Door2.CFrame + Door2.CFrame.lookVector * 4}
local DoorClose1 = {CFrame = Door1.CFrame }
local DoorClose2 = {CFrame = Door2.CFrame }
local open1 = TS:Create(Door1, TI, DoorOpen1)
local close1 = TS:Create(Door1, TI, DoorClose1)
local open2 = TS:Create(Door2, TI, DoorOpen2)
local close2 = TS:Create(Door2, TI, DoorClose2)
local sound = script.Parent["BMRF Sliding Door Open"]
local closesound = script.Parent["BMRF Sliding Door Close"]
game.ReplicatedStorage.OpenKeyDoor.OnServerEvent:Connect(function()
if opened == false then -- is it OPEN...?
if debounce == false then -- then check debounce
debounce = true
opened = true
neon.BrickColor = BrickColor.new("Bright green")
neonb.BrickColor = BrickColor.new("Bright green")
sound:Play()
open1:Play()
open2:Play()
wait(1) -- wait a bit (optional)
debounce = false -- reset the debounce
end
elseif opened == true then
if debounce == false then -- same thing as above
debounce = true
opened = false
neon.BrickColor = BrickColor.new("Really red")
neonb.BrickColor = BrickColor.new("Really red")
closesound:Play()
close1:Play()
close2:Play()
wait(1)
debounce = false
end
end
end)

4 comments
Would upvote if I could ngl
If you accept my answer, That would be nice too!
Thank you so much!
No problem