hatsfolder = Instance.new("Folder",game.lighting)
hatsfolder.Name = "Hats Storage"
function RemoveHats(hit)
if hit.Parent:findFirstChild("Humanoid") then
local char = hit.Parent
local name = (char.Name .. "'s Hats")
local lighting = (game.Lighting["Hats Storage"])
local parent = (lighting..game)
for i,v in pairs(game.Lighting:GetChildren()) do
if v.Name == "Hats Storage" then
for i,c in pairs(v:GetChildren()) do
if c.Name == (name) then
local HatsModel = Instance.new("Model",hatsfolder)
HatsModel.Name = (hit.Parent.Name .. "'s Hats")
end
end
end
end
for i,v in pairs(char:GetChildren()) do
if v.ClassName == "Accessory" then
v.Parent = parent
end
end
end
end
part.Touched:Connect(RemoveHats)
I get an error saying "attempt to concatenate field 'Hats Storage' (a userdata value)" "part" is made earlier in the script.
What I am trying to do is make a folder in lighting, then when someone touches a part, their hats get removed and a model gets made in the folder called "(their name + 's hats)". The hats should move to the model but the model isn't made, only the folder.

2 comments
Thanks but I did it a different way and it works now. But why should I use FindFirstChild instead of findFirstChild? They both work.
Like :connect , it is all deprecated.Deprecated things will not work