Infinite Yield on ServerStorage:WaitForChild("Paper1") even though it exists

  1. What do you want to achieve? Keep it simple and clear!
    Im making a system where it would load the tool that the player had before leaving the game. Basically a tool saving system
  2. What is the issue? Include screenshots / videos if possible!
    It keeps saying “Infinite yield possible on ‘ServerStorage:WaitForChild(“Paper1”)’” even though “Paper1” exists
    Here is the script:
while true do
	game.ServerStorage:WaitForChild("Paper"..tostring(game.Players.LocalPlayer:WaitForChild("SecretFolder").Paper.Value+1)):Clone().Parent = game.Players.LocalPlayer.Backpack
	if game.Players.LocalPlayer.Backpack:WaitForChild("Paper"..tostring(game.Players.LocalPlayer:WaitForChild("SecretFolder").Paper.Value+1)) then
		break
	end
end

EDIT: After some time of debugging. This is what i came up:

game.Players.PlayerAdded:Connect(function(plr)
          game.ReplicatedStorage.RemoteEvent1:FireClient(plr)
end)

Local script:

local plr = game.Players.LocalPlayer
game.ReplicatedStorage.RemoteEvent1.OnClientEvent:Connect(function()
	while true do
		print("a")
		local PaperTool = game.ReplicatedFirst:FindFirstChild("Paper"..(plr.SecretFolder.Paper.Value+1)):Clone()
		PaperTool.Parent = plr.Backpack
		print("ab")
		if plr.Backpack:FindFirstChild("Paper"..tostring(plr.SecretFolder.Paper.Value+1)) then
			print("break loop")
			break
		end
	end
end)

For some reason it prints “break loop” despite still not having the tool stored in my inventory

1 Like

Try using FindFirstChild instead of WaitForChild.

Tried it. But it gives me an error called “attempt to index nil with ‘Clone’”

Oh yeah my bad for the misinformation in the title. Paper1 does exist in ServerStorage

a

LocalScripts can not access server storage. Either way, cloning would be client sided and the tool would not work.

1 Like

It works but the tool sometimes dissapears

Either way, you should clone it from the server.

Thats what i did. But sometimes it gives me the tool and sometimes it does not

Add print statements to make sure it’s running

Tried it and it does print it. But it still didn’t give me the tool

I tried checking server storage while i was playing when it didn’t give me the tool and the tool still exists in Server storage

I have a question, can players have multiple items or only 1?

When a tool is not equipped you find it in PlayerBackpack

but when a tool is equipped you find it in Player.Character

Players can only have 1 tool since its a simulator game

Okay and are they forced to equip it or they can unequip it

They can unequip it. Equipping it will add a new functionality (clicking to get a stat, basically like a lifting simulator game)

Okay, but the thing is you are requiring server_storage from local script and you can’t, use remotes events and remote function

Yes i know, someone told me that and i fixed it

Okay but now, if the tool is equipped you will not find it because it’s in player character. Instead, unequipped tools can be found in backpack

The tool literally gets in the backpack when you join

This is probably a local script, and the client can’t see the children of server storage.