WaitForChild returns nil

How can I access this module script that’s inside the replicated storage

The issue is that waitforchild returns nil, even though I spelled it correctly
I have tried putting the the 2nd parameter for waitforchild but it still doesn’t work

image

local rs = game:GetService("ReplicatedStorage")

local spinnerContents = rs:WaitForChild("SpinnerContents", 3)

print(spinnerContents)
1 Like
local spinnerContents = require(rs:WaitForChild("SpinnerContents", 3))
1 Like

OP is not asking how to require a module, but that when he tries to reference it he gets nil value.

1 Like

Make sure that the SpinnerContents module exists at the time the script executes, also remove the 3 second timeout from the WaitForChild method call as this won’t help in that situation.

1 Like

thanks for replying, but I’m not sure how I can do it

Hastily copy pasted, but you know what I meant. He wasn’t requiring the module. I just tried doing the same thing with a module that didn’t have a return value and one that errored. Both still returned the name of the module, so something’s up with this.

1 Like

Try checking if the script even exists at run-time, because it should still print out the name of the module regardless of any errors. Another script could possibly be deleting it, just a guess

1 Like

thanks for helping ,when I test it in game I get this and the only script I have in the game doesn’t delete it

image

Try making a repro file, or just insert a new blank baseplate and create a module script in replicated storage and a script anywhere requiring it. This kind of behaviour is unexpected

1 Like

Thanks It works in a new baseplate but it doesn’t work in the one I had originally also how do you make a repro file?

It’s just a file with the bare minimum scripts to reproduce the behaviour you’re describing. Maybe try sending the SpinnerContents module because I can’t recreate this behaviour myself. Maybe something’s up with the script?

local contents = {}
contents["Crates"] = 25; 

function contents:GetItemTypes()
	local itemTypes = { 
		{
			Rarity = {Name = "Common", Chance = 0.589, Color = Color3.fromRGB(0, 85, 127)};
			Items = { 
				{Name = "Venomshank", GearId = "1"};
				{Name = "Darkheart", GearId = "2"};
				{Name = "Illumnia", GearId =  "3"};  
			}
			
		
			
			
			
		};
		
		{ 
			Rarity = {Name = "Rare", Chance = 0.411, Color = Color3.fromRGB(43, 125, 43)};
			Items = { 
				{Name = "God", GearId = "2"}; 
				{Name = "Cool" , GearId = "4"}
				
				
			}
			
			
		};	
	}; 
	
	for groupIndex, group in pairs(itemTypes) do 
		for i, item in pairs(group.Items) do 
			item.GroupIndex = groupIndex 
		end

That’s really, really strange. Even though you’re not returning contents and the loop isn’t closed (maybe it’s just a snippet, though), the script still returns for me. Trying parenting it to something like ReplicatedFirst, renaming it, and requiring it form a totally new and different script.