Script only works sometimes

I’m making a script that loads items into the shop which are stored in folders inside of replicated storage, but it sometimes can’t find the “Lightning Skins” folder inside the “Shop” folder, but sometimes it can, I have no idea why it does this, any help is appreciated!


image

Maybe you should use 'WaitForChild" Instead of “FindFirstChild” At this line
'Local findgroup=game:GetService(Replicated Storage) :WaitForChild(“Shop”) :FindFirstChild(group) ’
The reason I say this because WaitForChild waits for 5 seconds till it finds it but findFirstChild will not wait,
Why use WaitForChild?
Sometimes game takes time to load everything in the game so try ‘WaitForChild’ . Btw I still didn’t test see if it would work.

I tried that then 5 seconds later it printed Infinite yield on WaitForChild() when it decided not to work

I think I’ve fixed it!

1 Like
function LoadItems(group)
local findgroup = RepShop:FindFirstChild(group)

--- blah blah blah
end

this may be cuz there is no group also mind sending the whole script in code block form and not image form?

//this is a java code block!

This is a very late reply, however, I might have figured out this problem for anyone having similar issues. I had the same problem but I added in a simple

game.Players.PlayerAdded:Wait()

and it worked every time after that.