#Door CollectionService

13 messages · Page 1 of 1 (latest)

copper wasp
#

So my game consists of alot of doors. And i thought that using collectionservice to script these doors would be a good way. In the end, my script isn't working and I don't know how to fix it. I asked my friend and he told me collectionservice wasn't a good way to script doors. Is there a better way? Is putting a script in each and every door the best way?

dense pagoda
copper wasp
dense pagoda
#

its better than scripting like 20 scripts that basically does the same if the doors are doing the same thing

copper wasp
#

Can you help me with my script then, if that's the better solution because that's what I'm doing

#

using collection service

dense pagoda
#

it goes for the same for using that for npc and a Dropper Sim

copper wasp
#
local TweenService = game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")



local AnimsFolder = ServerStorage:WaitForChild("Animations")
local Animation = AnimsFolder:WaitForChild("OpenDoor")

local SoundsFolder = ServerStorage:WaitForChild("Sounds")
local Sound = SoundsFolder:WaitForChild("OpenDoor")


local DoorModel = CollectionService:GetTagged("Doors")
local hinge = DoorModel.Hinge
local MainDoor = DoorModel.MainDoor
print(MainDoor)

local prompt = MainDoor:WaitForChild("OpenPrompt")

local CFrameValue = DoorModel.OrientationValue.Value.Rotation



local OpenDoorTrack


local goalOpen = {}

goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)





local goalClose = {}


goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)

local tweenInfo = TweenInfo.new(0.5)

local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)

local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)



for _, door in pairs(DoorModel:GetDescendants()) do
    prompt.Triggered:Connect(function(player)
        local char = player.Character
        local hum = char:WaitForChild("Humanoid")
        OpenDoorTrack = hum:LoadAnimation(Animation)

        if prompt.ActionText == "Close" then

            OpenDoorTrack:Play()
            tweenClose:Play()
            Sound:Play()


            prompt.ActionText = "Open"

        else

            OpenDoorTrack:Play()
            tweenOpen:Play()
            Sound:Play()


            prompt.ActionText = "Close"

        end
    end)
    
    
end

#

ServerScriptService.DoorHandler:19: attempt to index nil with 'WaitForChild' is my erroe

#

local DoorModel = CollectionService:GetTagged("Doors")
local hinge = DoorModel.Hinge
local MainDoor = DoorModel.MainDoor
print(MainDoor)

local prompt = MainDoor:WaitForChild("OpenPrompt")

#

It's basically saying that maindoor is nil, but it doesn't make sense because maindoor is in every single door that is tagged

#

even when i print maindoor it says nil

rocky wadiBOT
#

studio** You are now Level 1! **studio