I want to make a system in which when you close a door by activating a ProximityPrompt, it remains closed for 10 seconds, and then it reopens automatically (but instead of doing this, what I actually do is delete the door and generate a new one already open), for a temporary defense system
The problem is that for some reason the door is generated correctly in the previous door position, but the door that should be deleted (which is supposed to be the door that is Parent of the ProximityPrompt that I activated), is actually the door of the previous ProximityPrompt that I activated is the one that is deleted.
for i, doorPrompt in workspace.Map:FindFirstChildOfClass("Folder"):FindFirstChild("Doors"):GetDescendants() do
if doorPrompt:IsA("ProximityPrompt") and doorPrompt.Parent.Parent.Parent:FindFirstChild("DoorType") and doorPrompt.Parent.Parent.Parent:FindFirstChild("DoorType").Value == "USABLE OPEN" then
--local doorPrompt = instance
if doorPrompt then
if doorPrompt then
doorPrompt.ActionText = "Close for " .. timeClosed .. " Seconds " .. "(" .. DoorsPrice.Value .. ")"
doorPrompt.Triggered:Connect(function(plr)
if plr.Coins.Value >= DoorsPrice.Value then --and canClose == true then
canClose = false
plr.Coins.Value -= DoorsPrice.Value
DoorsPrice.Value = DoorsPrice.Value * 2
doorPrompt.Enabled = false
print("Reseting door...")
task.wait(10)
for i, sameDoorClone in workspace["Assets"].Doors:GetDescendants() do
if sameDoorClone:IsA("Model") and sameDoorClone.Name == doorPrompt.Parent.Parent.Parent.Name then
sameDoorClone.PrimaryPart.CFrame = doorPrompt.Parent.Parent.Parent.PrimaryPart.CFrame
task.wait(1)
end
end
doorPrompt.Parent.Parent.Parent:Destroy() --THIS line is the problem or something
print("Door reset!")
canClose = true
--doorPrices()
task.spawn(function()
end)
end
end)
end
end
end
end
i tried with Task.Spawn, i tried changing the system completely to Workspace.Map.DescendantAdded, nothing works, i even tried to instead of destroying the model, just change its Parent to ReplicatedStorage or something so it wouldn’t be seen
I should mention that the doors already have a system so that when the ProximityPrompt is activated the door closes, that script belongs to the individual door, but I wanted to make this system general and detect all the doors on the map at the same time.