Door with AutoClose value Enabled broken

  1. What do you want to achieve?
    Resolve the issue “Door with AutoClose value Enabled broken”

  2. What is the issue?
    The door with AutoClose value enabled is broken, I suppose the issue is caused by task.wait() function in the for _,[index] loop

Videos and screenshots


https://im4.ezgif.com/tmp/ezgif-4-f9511a75a1.gif

  1. What solutions have you tried so far?
    A lot

Door’s OOP Code

--// Initialisation

local CollectionService = game:GetService("CollectionService")
local ServerScriptService = game:GetService("ServerScriptService")
local Packages = ServerScriptService:WaitForChild("Packages")
local Authenticated = require(ServerScriptService:WaitForChild("Packages"):WaitForChild("Authentication"):WaitForChild("Authentication Class"))

--// Variables

local Movers = {}
Movers.__index = Movers

--// Functions

function Movers:CheckAction()
	self.Prompt.ActionText = self.Open.Value and "CLOSE" or "OPEN"

	return self.Open.Value
end

function Movers:GetConstraint()
	local Constraints = {}

    for _, Array in next, self.Object:GetDescendants() do
	    if Array:IsA("Constraint") then
            table.insert(Constraints, Array)
		end
	end

    return Constraints
end

function Movers:SetClose()

	self.Open.Value = false
	self.Sound.SoundId = "rbxassetid://" .. self.SoundClose.Value
	self.Sound:Play()
	self:CheckAction()
	for _, Arrays in ipairs(self.Constraints) do
		if Arrays:IsA("PrismaticConstraint") then
            Arrays.TargetPosition = 0
        elseif Arrays:IsA("HingeConstraint") then
            Arrays.TargetAngle = 0
		end
    end
    
end

function Movers:SetOpen()
    if (self.Lockdown.Value) then return end
    
    self.Open.Value  = true
    
    self.Sound.SoundId = "rbxassetid://" .. self.SoundOpen.Value
    self.Sound:Play()
    
    self:CheckAction()
    
    for _, Array in ipairs(self.Constraints) do
        if ( Array:IsA("PrismaticConstraint") ) then
            if (self.AutoClose.Value) then
                
                self.Prompt.Enabled = false
                Array.TargetPosition = Array.UpperLimit

                task.wait(self.AutoCloseTime.Value)
                self:SetClose()
                self.Prompt.Enabled = true

            else
                Array.TargetPosition = Array.UpperLimit
            end
        elseif (Array:IsA("HingeConstraint")) then
            if (self.AutoClose.Value) then
                
                self.Prompt.Enabled = false
                Array.TargetAngle = Array.UpperAngle
                
                task.wait(self.AutoCloseTime.Value)
                self:SetClose()
                self.Prompt.Enabled = true
                
            else
                Array.TargetAngle = Array.UpperAngle
            end
        end
    end
    
end

function Movers:SetLockdown()
	if self.Open.Value then
        self:SetClose()
        self.Lockdown.Value = true
	end
end

function Movers.new(Object, TargetValue)
	
    --// Setup
	
	local self = setmetatable({}, Movers)

	self.Object = Object
    self.Configuration = self.Object:FindFirstChild("Configuration")
    
    self.Open = self.Configuration:FindFirstChild("Open")
	self.Lockdown = self.Configuration:FindFirstChild("Lockdown")
    self.Permissions = self.Configuration:FindFirstChild("Permissions")
    self.AutoClose = self.Configuration:FindFirstChild("AutoClose");
    self.AutoCloseTime = self.Configuration:FindFirstChild("AutoCloseTime");
    
    self.Sound = Instance.new("Sound", self.Object.PrimaryPart)
    self.SoundClose = self.Configuration:FindFirstChild("SoundClose")
    self.SoundOpen = self.Configuration:FindFirstChild("SoundOpen")
    self.Sound.RollOffMaxDistance = 100
	
	self.MovingPosition = 0

    self.Constraints = self:GetConstraint()

	self.Prompt = self.Object:WaitForChild("Interaction"):WaitForChild("ProximityPrompt")
	self.Prompt.ObjectText = "DOOR"
	
    --// Signals
    
    self.Prompt.Triggered:Connect(function(Player)
        if self.Permissions and not Authenticated(Player, self.Permissions) then return end
        if not self.Open.Value then self:SetOpen(TargetValue) else self:SetClose() end
    end)

    self.Lockdown.Changed:Connect(function()
        self:SetLockdown(self.Lockdown.Value)
    end)
	
	self:CheckAction()
	if self.Open.Value == true then self:SetOpen(self.MovingPosition) end

	return self
end

return Movers 

This issue has been fixed, I realised you can’t use task.wait() in for loops

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.