Ultimately, I wanted a door to open with tweens for aesthetic reasons. However, I am not skilled enough to really figure this out. Apparently not skilled enough to do this simple script either as I’ve been at this for hours now.
I’ve settled on a goal to make all parts of this door go invisible and make a “dummy door” so that it looks like it opens instantly. (Similar to how minecraft works) One door model is transparent and you can collide, then vice versa when it’s opened.
Below is the code I’m using, and I can’t seem to get all the parts within this model to vanish when the “hitbox” part is touched.
local Door = script.Parent.Parent:GetChildren()
local ButtonDebounce = false
local DoorDebounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") and not DoorDebounce and not ButtonDebounce then
for i = 1, #Door do
DoorDebounce = true
ButtonDebounce = true
Door.CanCollide = false
Door.Transparency = 1
task.wait(5)
DoorDebounce = false
ButtonDebounce = false
end
end
end)
I think you nearly answered your whole question on your own. Perhaps you can :GetChildren() and use a for loop to make all parts inside the model invisible via Transparency?
local Door = script.Parent.Parent:GetChildren()
local ButtonDebounce = false
local DoorDebounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") and not DoorDebounce and not ButtonDebounce then
for i, v in pairs(Door) do
DoorDebounce = true
ButtonDebounce = true
v.CanCollide = false
v.Transparency = 1
task.wait(5)
DoorDebounce = false
ButtonDebounce = false
end
end
end)
You’re only iterating over the number of doors, not the doors themselves, if you get what I mean. Using a for loop is the right call, but you forgot something :
DoorDebounce = true -- place the debounce outside of the loop
ButtonDebounce = true
task.delay(5, function() -- use task.delay to delay resetting the debounce values
DoorDebounce = false
ButtonDebounce = false
end)
-- go through every door in the Door array
for i = 1, #Door do
local door = Door[i] -- this is what you forgot
-- checking the object's name because door parts are named "Door" in your model
if door.Name == "Door" then
door.CanCollide = false
door.Transparency = 1
task.wait(5)
-- make the part visible and collidable again (idk if this was intentional)
door.CanCollide = true
door.Transparency = 0
end
end