Collection Service problem

  1. I Want to make doors that open and Close, I Am using collection service for the thing to not duplicate the scripts.

  2. In the collection service script I have made a debouncer, Now, All of the doors in the game must wait for the debouncer to be able to open.

local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local Debouncer = false

for Index, Proximity: ProximityPrompt in CollectionService:GetTagged("Gaurds Buttons.") do
	Proximity.Triggered:Connect(function(Player)
		for _, Object in Player.Backpack:GetChildren() do
			if Object.Name == "Key spell." and not Debouncer then
				local OpenSound = Instance.new("Sound")
				OpenSound.SoundId = "rbxassetid://833871080"
				
				local CloseSound = Instance.new("Sound")
				CloseSound.SoundId = "rbxassetid://7038967181"
				
				print("Working.")
				Debouncer = true
				local PrimaryPart: Part = Proximity.Parent
				OpenSound.Parent = PrimaryPart
				CloseSound.Parent = PrimaryPart
				local Model: Model = PrimaryPart.Parent 
				local RotationPart: Part = PrimaryPart.Parent["Turning Part."]
				local TweenInformation = TweenInfo.new(1, Enum.EasingStyle.Cubic)
				local OldCFrame = PrimaryPart.Position
				PrimaryPart.Position = RotationPart.Position
				local RotatingTween = TweenService:Create(PrimaryPart, TweenInformation, {CFrame = PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0)})
				RotatingTween:Play()
				OpenSound:Play()
				RotatingTween.Completed:Wait()
				local UnRotatingTween = TweenService:Create(PrimaryPart, TweenInformation, {CFrame = PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-90),0)})
				UnRotatingTween:Play()
				CloseSound:Play()
				UnRotatingTween.Completed:Wait()
				PrimaryPart.Position = OldCFrame
				Debouncer = false
			end
		end
	end)
end

Instead of a single debounce variable, make a table where you’ll insert something unique like the name of the prompt to.

Then when checking debounce, just check if the name of the prompt or whatever else you chose is true inside that table.

local Debounce = {}

-- Set debounce active
Debounce[Prompt.Name] = true

-- Set debounce inactive
Debounce[Prompt.Name] = nil -- you can either set this to nil or false
1 Like

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