(video of my door working) https://gyazo.com/ccd0dde5f7c5d22eab143cf2da7e4763
So what I am doing now is using two invisible and not collideable parts to detect if player is inside the building or not. Because you don't want your player to be stuck between door and wall. But .Touched
Events is not very trustworthy so I want to use different method. Can you give me better methods?
local Players = game:GetService("Players") local Debounce = false local Open = false local inc = 1/10 local center = script.Parent.Parent.Center script.Parent.PrimaryPart = script.Parent.Hinge local TweenService = game:GetService("TweenService") local Info = TweenInfo.new(.3) local goals = { CFrame = script.Parent.PrimaryPart.CFrame * CFrame.Angles(0,-math.rad(90),0) } local VAPE = TweenService:Create(script.Parent.PrimaryPart, Info, goals) local CloseSound = Instance.new("Sound", script.Parent) CloseSound.SoundId = 'rbxassetid://192416584' CloseSound.Volume = 1 local OpenSound = Instance.new("Sound", script.Parent) OpenSound.SoundId = 'rbxassetid://320946744' OpenSound.Volume = 1 local function tweenModel(model, CF) local CFrameValue = Instance.new("CFrameValue") CFrameValue.Value = model:GetPrimaryPartCFrame() CFrameValue:GetPropertyChangedSignal("Value"):connect(function() model:SetPrimaryPartCFrame(CFrameValue.Value) end) local tween = TweenService:Create(CFrameValue, Info, {Value = CF}) tween:Play() tween.Completed:connect(function() CFrameValue:Destroy() end) end Players.PlayerAdded:Connect(function(player) print(player.Name.." found") script.Parent.Parent.Trigger1.Touched:Connect(function(hit) if Debounce == false then Debounce = true if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then print("Humanoid found") if Open == false then tweenModel(script.Parent, script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, -math.rad(90), 0)) OpenSound:Play() wait(.3) Open = true end end repeat wait() until 7 <= (center.Position - player.Character.HumanoidRootPart.Position).magnitude if Open == true then tweenModel(script.Parent, script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0)) wait(.3) CloseSound:Play() Open = false end Debounce = false end end) script.Parent.Parent.Trigger2.Touched:Connect(function(hit) if Debounce == false then Debounce = true if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then print("Humanoid found") if Open == false then tweenModel(script.Parent, script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0)) OpenSound:Play() wait(.3) Open = true end end repeat wait() until 7 <= (center.Position - player.Character.HumanoidRootPart.Position).magnitude if Open == true then tweenModel(script.Parent, script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, -math.rad(90), 0)) wait(.3) CloseSound:Play() Open = false end Debounce = false end end) end)