Why is "WaitForChild()" so unreliable?

I’m trying out certain features while reading the documentation. In this situation the “Bindable Event” object

When running the script its about a 50/50 chance of the script actually firing

I tried copy-pasting the example script from the documentation just in case my script was wrong, but I got the same result

Scripts:

Event Firing script:

local ServerScriptService = game:GetService("ServerScriptService")
local TestBindableEvent = ServerScriptService:WaitForChild("TestBindableEvent")
TestBindableEvent:Fire("Ball")

Event Connection script:

local ServerScriptService = game:GetService("ServerScriptService")
local TestBindableEvent = ServerScriptService:WaitForChild("TestBindableEvent")

TestBindableEvent.Event:Connect(function(shape)
	print("Signal recieved")
	local part = Instance.new("Part")
	part.Shape = shape
	part.Parent = workspace
	part.Position = Vector3.new(0,10,0)
end)
1 Like

WaitForChild is actually the same as referencing as Parent.Child, but it won’t throw error if object not yet created. In your case, script1 loads BEFORE script2, and thus it fires bindable event while second script not functional yet. This results in dropped event. Give game time to load to solve this issue.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.