I’m trying to create a more streamlined and optimized script for doors in a large game I’m developing,
using CollectionService, if possible.
I already have a script that works independently of CollectionService, but I’d like to use the CollectionService for ease of access and control, and less scripts. Here’s my unoptimized and non-CollectionService door script, that’d like to convert to let it work with it, but I have no clue how to make the collection service work with it, along with sound. If someone could help optimize it and lower the lines of code, that’d help too.
local handle = script.Parent.Clicker.Interactive
local doorOpen = false
local changingState = falsehandle.ClickDetector.MouseClick:Connect(function()
if doorOpen == true and changingState == false then
changingState = true
for i = 1, 14 do
script.Parent.Door1:SetPrimaryPartCFrame(script.Parent.Door1.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(5.8), 0))
script.Parent.Door2:SetPrimaryPartCFrame(script.Parent.Door2.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(-5.8), 0))
wait()
end
script.Parent.Sounds.DoorOpen:Play()
changingState = false
doorOpen = false
elseif changingState == false then
changingState = true
for i = 1, 14 do
script.Parent.Door1:SetPrimaryPartCFrame(script.Parent.Door1.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(-5.8), 0))
script.Parent.Door2:SetPrimaryPartCFrame(script.Parent.Door2.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(5.8), 0))
wait()
end
script.Parent.Sounds.DoorClose:Play()
changingState = false
doorOpen = true
end
end)