-
I Want to make doors that open and Close, I Am using collection service for the thing to not duplicate the scripts.
-
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