-
Ive been trying to create a for loop to automate proximityprompts for drawers for a horror game
-
The issue is that when I use Getchildren() it doesn’t return instances
-
I’ve tried adding wait(5) and checking if there are more then 1 children in the table and etc
wait(5)
-- >> Services
local ReplicatedStorage = game:GetService('ReplicatedStorage');
local TweenService = game:GetService('TweenService');
-- >> Variables
local Cupboards = game:GetService('Workspace'):WaitForChild('Cupboards');
-- >> Functions
-- Testing
local function PlaySound(Sound: Sound, Part: BasePart)
if (Part) then
Sound:Clone()
Sound.PlayOnRemove = true;
Sound.RollOffMaxDistance = 100;
Sound.Volume = 1;
Sound.Parent = Part
end
Sound:Destroy();
end
local function SetupCupboards()
if Cupboards then -- Passes this
print('Initiating Cupboards'); -- Prints this
end
for i,v in pairs(Cupboards:GetChildren()) do
print(i,v); -- Doesnt print this at all please help
if v.Name == 'Cupboard' then
local CupboardHolder = v
print('There is a cupboard holder');
for _, Cupboard in pairs(CupboardHolder:GetChildren()) do
if Cupboard:GetAttribute('Setup') then return end
Cupboard:SetAttribute('Setup', true)
Cupboard:SetAttribute('State', 'Closed');
Cupboard.ActionText = 'Open';
Cupboard.ProximityPrompt.Triggered:Connect(function()
local CupboardState = Cupboard:GetAttribute('State')
if CupboardState == 'Closed' then
PlaySound(Cupboard:WaitForChild('Open'), Cupboard);
Cupboard.ActionText = 'Close';
elseif CupboardState == 'Opened' then
PlaySound(Cupboard:WaitForChild('Close'), Cupboard)
Cupboard.ActionText = 'Open';
end
end)
end
end;
end
end
repeat task.wait() until #Cupboards:GetChildren() >= 1 -- It passes this part
print("Number of Cupboards:", #Cupboards:GetChildren()) -- It prints 3
print(Cupboards:GetChildren()) -- This prints nothing at all
SetupCupboards()
Also I’ve turned off streaming enabled and streaming enabled doesn’t seem to be the issue