Script being real silly, script stops running when requiring

So when I try to require a module in my script it just stops running at that point heres my code

local UserInputService = game:GetService("UserInputService")
local ProximityPromptService = game:GetService("ProximityPromptService")
local TweenService = game:GetService("TweenService")
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local rstorage = game:GetService('ReplicatedStorage')

local LocalPlayer = Players.LocalPlayer

local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local modules = rstorage:WaitForChild('Modules',30)

local setups = modules:FindFirstChild('Setup')
print(modules,setups) -- this prints both things and neither are nil
print('GETTING MODULE') -- this prints
local setupProp = require(setups:FindFirstChild('SetupProp')) -- stops here, after this nothing runs

print('Happening')
setupProp.setupClientPrompts(LocalPlayer)

There arent any errors so like I have no idea why this is happening. This is in a local script parented to StarterPlayerScripts, whats going on?

3 Likes

Could you take a screenshot of the setups module with all of its children?

2 Likes

image_2024-06-25_170050263

1 Like

This just means that there’s an infinite yield/loop in your SetupProp module before the return statement.

1 Like

Well uh how do I fix that then? I thought how I was doing it now it should work but ok.
Should I just replace waitforchild with findFirstChild?

1 Like

A few misconceptions I want to clear up:

  1. If your LocalScript is located in a container that can run (i.e. PlayerScripts) and is not in ReplicatedFirst, all Instances that are statically placed (i.e. the ones that are published in Studio aside from workspace and server containers) will guarantee to exist before the LocalScript even runs. This means there is no need to use WaitForChild.
  2. You are using FindFirstChild incorrectly. In your case, you are assuming the returned value always exist, which is false. It may be always true in this case, but you can simply index via dot operator (i.e. ReplicatedStorage.Modules.Setup).

For your solution, something inside your SetupProp is yielding. Open it up to see what is happening before returning something.

1 Like

Try doinglocal setupProp = require(setups:WaitForChild('SetupProp') instead

1 Like

Well I tried your approach I might have done what you said but not sure 100%

local UserInputService = game:GetService("UserInputService")
local ProximityPromptService = game:GetService("ProximityPromptService")
local TweenService = game:GetService("TweenService")
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local rstorage = game:GetService('ReplicatedStorage')

local LocalPlayer = Players.LocalPlayer

local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local modules = rstorage.Modules

local setups = modules.Setup
print(modules,setups)
print('GETTING MODULE')
local setupProp = require(setups.SetupProp)

print('Happening')
setupProp.setupClientPrompts(LocalPlayer)

Anyhow it doesnt work.

Heres the stuff in the module:

-- services
local tagService = game:GetService('CollectionService')

-- modules
local searchablesModule = require(script:WaitForChild('Searchables',30))
local promptsModule = require(script:WaitForChild('Prompts',30))

local module = {}

module.SetupSearchables = function() 
	wait(0.5)
	local searchables = tagService:GetTagged('Searchable')
	
	for _, obj:BasePart in searchables do
		searchablesModule.setupSearchable(obj)
	end
end

module.SetupPrompts = function()
	local dess = workspace:GetDescendants()
	
	for _, prompt in dess  do
		if prompt:IsA('ProximityPrompt') then
			promptsModule.SetupPrompt(prompt)
		end
	end
	
	workspace.DescendantAdded:Connect(function(prompt)
		if prompt:IsA('ProximityPrompt') then
			promptsModule.SetupPrompt(prompt)
		end
	end)
end

module.setupClientPrompts = function(player:Player)
	print('LOADING PROMPTS FOR CLIENT')
	searchablesModule.HandleSearchablesClient(player) -- if this is here or not, still nothing
end

return module
1 Like

This changed nothing as from my info the 30 in there will only stop the wait from yielding for ever.

Yes I did try it, no it didnt work

1 Like

Is there doc references for #1? I’m always overly-cautious when writing code that will reference anything outside of the script itself. Just wanna know where you learned that :slight_smile:

1 Like

No I dont have any document references for this. I think thats what you mean correct me if Im wrong
Oh you werent talking to me my bad lol

1 Like

Then check your Searchable module and Prompts module if that is yielding as well.

Sure, let me try to find it. It was an admin post somewhere here.

2 Likes

Ahh I see there are waitForChilds in the module, ill try removing them to see if it works

1 Like

Ok well that didnt work either, any ideas?

1 Like

I meant check inside those modules and see if there’s anything yielding there as well.

I couldn’t find the admin post, but here’s a snippet from this documentation link: DataModel | Documentation - Roblox Creator Hub

This function returns true if the client has finished loading the game for the first time.
When all initial Instances in the game have finished replicating to the client, this function will return true.
Unless they are parented to ReplicatedFirst, LocalScripts will not run while the game has not loaded.

1 Like

I’ve removed anything that could be yielding the scripts or modules. Same problem.
AGGHHHH

That is on you to figure out, not us.

Consider this pattern:
ModuleA → returns {}
ModuleB → requires ModuleA, while true do, returns {},
ModuleC → requires ModuleB, returns {}
Script → requires ModuleC

  1. The Script will run, requiring ModuleC
  2. ModuleC will run, requiring ModuleB,
  3. ModuleB will run, requiring ModuleA,
  4. ModuleA will run, finally ending the require steps, returning {}, going back to ModuleB
  5. ModuleB will infinitely yield due to the while true do

Try removing everything from the modules (so just have local module = {} return module) and slowly add back parts of it until it stops working, then whatever you added back last would tell your what is causing the problem.

Ok you’re right about the yielding part, I used a module that has the actual code I use and it works perfectly so Ill try trial and error to figure out why this is happening

Doing this I can say, nothing changed either so like yeah weird.