Need help with an error

I need help with this error. I’ve tried a lot of things to fix it. But it won’t fix

Output -
Screen Shot 2022-12-22 at 3.09.55 PM

Script

local respawnFolder = script.ToolsForRespawn
local player = game:GetService("Players").LocalPlayer
local backpack = player:WaitForChild("Backpack")
local LoadoutEvent = game:GetService("ReplicatedStorage"):WaitForChild("CharacterEvents").SendLoadout
local LoadoutFolder = game:GetService("ServerStorage"):WaitForChild("CharacterLoadouts", 0.1)

LoadoutEvent.OnClientEvent:Connect(function(loadout)
	local loadout_ = LoadoutFolder:FindFirstChild(loadout):GetChildren()
	for amount, tool in ipairs(loadout_) do
		local cloneTool = tool:Clone()
		cloneTool.Parent = respawnFolder
	end
end)

player.CharacterAdded:Connect(function()
	local loadout_ = respawnFolder:GetChildren()
	for amount, tool in ipairs(loadout_) do
		local cloneTool = tool:Clone()
		cloneTool.Parent = backpack
	end
end)
local respawnFolder = script.ToolsForRespawn
local player = game:GetService("Players").LocalPlayer
local backpack = player:WaitForChild("Backpack")
local LoadoutEvent = game:GetService("ReplicatedStorage"):WaitForChild("CharacterEvents").SendLoadout
local LoadoutFolder = game:GetService("ServerStorage"):WaitForChild("CharacterLoadouts")

LoadoutEvent.OnClientEvent:Connect(function(loadout)
	local loadout_ = LoadoutFolder:FindFirstChild(loadout):GetChildren()
	for _, tool in ipairs(loadout_) do
		local cloneTool = tool:Clone()
		cloneTool.Parent = respawnFolder
	end
end)

player.CharacterAdded:Connect(function()
	local loadout_ = respawnFolder:GetChildren()
	for _, tool in ipairs(loadout_) do
		local cloneTool = tool:Clone()
		cloneTool.Parent = backpack

	end
end)

Where is amount specified?

Edit I see @StraightScared covered that.

Now it just says “Infinite Yield”

Looks like on line 5, when you “WaitForChild”, the child isn’t being found within the 0.1 seconds you give it.

Try removing the 0.1 & see what happens.

When I remove the 0.1 It breaks and gives me “Infinite Yield” warning

Can you just use FindFirstChild or is it not already a child of ServerStorage?

It’s already a child of ServerStorage. It’s a folder. But I’ll try to use FindFirstChild instead. And see what happens

Alright. Let me know if it works.

(Or you could just do game.ServerStorage.CharacterLoadouts)

If this is a LocalScript and CharacterLoadouts is in ServerStorage at run time it will not replicate to the client, so it never exists. ServerStorage is only meant to be used by the server, not clients. Try moving it to ReplicatedStorage instead.

It seems that this line

	local loadout_ = LoadoutFolder:FindFirstChild(loadout):GetChildren()

is giving the error of indexing nil with findfirstchild

Oh yeah, didn’t notice.

You can’t use serverstorage from the client.

I’ll try that. That might be the problem

You CAN access it, but nothing replicates from the server to the clients in it.

2 Likes

That fixed the problem. Thanks! Also Happy Holidays :slightly_smiling_face:!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.