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?
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.
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.
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
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
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.
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