I already made a script that uses click detection for my door. I want to change this though, by making it so that if the player walks in within 5 studs, the door will open without having to press the click detector. I find that the click detector isn't the best way to open a door in my opinion; and I'd like to open a door without even clicking on the door, but just walking towards/near it. When you're within 5 studs, the door should stay open; but I don't know how to do that. Here is my script:
local tween = game:GetService("TweenService")
local center = script.Parent.Center
local door = "Closed"
local CF = Instance.new("CFrameValue")
CF.Value = center.CFrame
CF.Changed:Connect(function()
center.CFrame = CF.Value
end)
local debounce = false
script.Parent.Door.ClickDetector.MouseClick:Connect(function()
if debounce == true then return end
debounce = true
if door == "closed" then
tween:Create(CF, TweenInfo.new(3, Enum.EasingStyle.Quart), {Value = center.CFrame * CFrame.Angles(math.rad(0),math.rad(90),math.rad(0))}):play()
door = "open"
else
tween:Create(CF, TweenInfo.new(3, Enum.EasingStyle.Quart), {Value = center.CFrame * CFrame.Angles(math.rad(0),math.rad(-90),math.rad(0))}):play()
door = "closed"
end
wait(3)
debounce = false
end)

2 comments
Yes it works, but there's this really strange bug. Do you have discord so that I can send you it, and that you can help me? Thanks.
You should use RunService which is basically a nanosecond while loop that doesn't crash your game