Hello, developers. Recently, I was introduced to this error. The code was working, until I tested it again and it suddenly stopped working and was erroring with attempting to call :FindFirstChild() on nil. So I replaced all the FindFirstChilds with WaitForChilds thinking it would work, but it didn’t. Here is the code.
local DOORMS = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Scripts = ServerStorage:WaitForChild("Scripts")
local ROBLOXMS = require(ReplicatedStorage:WaitForChild("ROBLOXMS"))
local ProximityHandler = Scripts:WaitForChild("ProximityHandler")
local Tunes = {
["Metal Door"] = {
Distance = 10,
Key = Enum.KeyCode.E,
GamepadKey = Enum.KeyCode.ButtonX,
RequireSight = true,
Name = "metal door"
},
}
function DOORMS.Init(DoorMain: Script, TuneName)
local Tunes = Tunes[TuneName]
local DoorSensor = DoorMain:FindFirstChild("DoorSensor")
local Door = DoorMain:FindFirstChild("SeperateDoor")
local MainSensor = DoorSensor:FindFirstChild("Main")
local ProximityPrompt = DOORMS.CreateDoorProximity(Tunes.Distance, Tunes.Key, Tunes.GamepadKey, Tunes.RequireSight)
ProximityPrompt.Parent = MainSensor
local ClonedProximityHandler = ProximityHandler:Clone()
ClonedProximityHandler.Parent = ProximityPrompt
ClonedProximityHandler.Enabled = true
end
function DOORMS.Shown(DoorSensor: Model) -- Client
local Neons = {
Neon1 = DoorSensor:FindFirstChild("Neon1"),
Neon2 = DoorSensor:FindFirstChild("Neon2"),
Neon3 = DoorSensor:FindFirstChild("Neon3")
}
for _,v in pairs(Neons) do
ROBLOXMS.TweenColor(Neons, Color3.fromRGB(0, 255, 0), 1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
end
end
function DOORMS.Hidden(DoorSensor: Model) -- Client
local Neons = {
Neon1 = DoorSensor:FindFirstChild("Neon1"),
Neon2 = DoorSensor:FindFirstChild("Neon2"),
Neon3 = DoorSensor:FindFirstChild("Neon3")
}
for _,v in pairs(Neons) do
ROBLOXMS.TweenColor(Neons, Color3.fromRGB(255, 0, 0), 1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
end
end
function DOORMS.Interact() -- ???
end
function DOORMS.CreateDoorProximity(Distance: number, Key: Enum.KeyCode, GamepadKey: Enum.KeyCode, RequireSight: boolean): ProximityPrompt
local ProximityPrompt = Instance.new("ProximityPrompt")
ProximityPrompt.MaxActivationDistance = Distance
ProximityPrompt.KeyboardKeyCode = Key
ProximityPrompt.GamepadKeyCode = GamepadKey
ProximityPrompt.RequiresLineOfSight = RequireSight
ProximityPrompt.Style = Enum.ProximityPromptStyle.Custom
return ProximityPrompt
end
return DOORMS
This is where everything is located.
DOORMS is located in ReplicatedStorage.
If this is in a LocalScript, ServerStorage does not exist on the client, even if you call :GetService(). You’ll have to switch it over to a server script, hence the service name “ServerStorage”. Move the needed instances to ReplicatedStorage if you need the client to be able to access them.
since DOORMS is a modulescript, it will inherit the type of the script that tried to retrieve the modulescript (serverscript/localscript). like @Wizzthepixelcat said, if you use a localscript, serverstorage does not exist cannot be viewed by the localscript and will be shown as empty. only serverside scripts can see instances inside ServerStorage and ServerScriptService.
It gets called by a server script first to init it. Anything that is commented ‘client’ is called by the client. You can assume anything else is called by a script.
The client calls it after init takes place, but the init isn’t taking place because of this.
i’m not fully sure what you are trying to say, but you definitely cant access the module from a localscript since it’s in serverstorage. anyway the solution is moving the scripts folder to like replicatedstorage or any other service that clients can see
Yes I did this before, I should have told you the results in the beginning.
It’s 0 children.
I’ll do some more testing, but nothing else is calling it. I think I might know why now, so I’ll get back to you after I test this thought.
i know you have mentioned that the problem got nothing to do with a localscript, but that’s a behavior of a clientsided script. anyway goodluck finding the problem here.
I’ve figured it out. The localscript is calling the module AFTER the script is done with the init function. I’m going to put all the server stuff in the server functions.