Attempt to index nil with "Name" placed in SSS

Okay, so recently I have been trying to make a uniform spawner in roblox that, when a player spawns in, it will remove all there accessories and give them a hat, tools and specific clothing based on their rank. Sadly, I keep getting an error, saying: “[attempt to index nil with ‘Name’]”. This error is occuring in both my local script and in my regular script. Both of these are placed in SSS, so I am wondering if that’s the problem. Any and all help is appreciated, so thank you in advance! :smile: Code will be posted below, thanks.

Script:

local players = game:GetService("Players")
local plaid = 5131370
local jcid = 5996731

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local folder = script:FindFirstChild(player.Team.Name)
		if folder then
			local tools = folder:FindFirstChild("Tools")
			if tools then
				for i,v in pairs(tools:GetChildren()) do
					v:Clone().Parent = player.Backpack
				end
			end
			
					if player:GetRankInGroup(5996731) <= 255 and folder then
						local clothes = folder.LR:FindFirstChild("Clothes")
							if clothes then
							for i,v in pairs(clothes:GetChildren()) do
					local clothing = character:FindFirstChild(v.Name)
					local db = true
					if clothing then
						clothing:Destroy()
					end
					v:Clone().Parent = character
					end
				end
			end
			
			local accessories = folder:FindFirstChild("Accessories")
			if accessories then
				for i,v in pairs(accessories:GetChildren()) do
					if v.Name == "Hat" then
						for _,eaccessories in pairs(character:GetChildren()) do
						if eaccessories:IsA("Accessory") then
								eaccessories:Destroy()
						end
							local g = v:Clone()
							g.Parent = character
						local C = g:GetChildren()
						if g then
							for i=1, #C do
			if C[i].className == "Part" then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
				g.Middle.Transparency = 1
			end
				local Y = Instance.new("Weld")
				Y.Part0 = character.Head
				Y.Part1 = g.Middle
				Y.C0 = CFrame.new(0, 0, 0)
				Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			h[i].Anchored = false
			h[i].CanCollide = false
		end
							end
						end
					end
				end
			end
		end
	end)
end)

--[[players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait()
		for i,v in pairs(game.Players:GetPlayers()) do
			local folder = script:FindFirstChild(v.Team.Name)
			if folder then
		local d = character:GetChildren()
		for i = 1,#d do
			if d[i]:IsA("Accessory") then
					d[i]:Destroy()
					end
				end
			end
		end
	end)
end)--]]

Local Script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait()
		local folder = script.Parent.Script:FindFirstChild(player.Team.Name)
		if folder then
			local d = character:GetChildren()
			for i = 1,#d do
				if d[i]:IsA("Accessory") then
					d[i]:Destroy()
				end
			end
		end
	end)
end)
1 Like

LocalScripts don’t run in SSS… It’s called ServerScriptService for a reason. The reason this errors, though, is probably because they aren’t necessarily in a team when they first spawn. Try checking if player.Team is actually a thing before checking its name.

3 Likes