I want to know another script where you can try the hats to. I made a script where if you want to try them on, you would click on try. But it gave an error. This is the script:
dist = 10 function onClicked() local players = game.Players:GetChildren() for i = 1, #players do if (players[i].Character.Torso.Position - script.Parent.Position).magnitude < dist then local name = players[i].Name local f = game.Workspace:FindFirstChild(name) local s = f:FindFirstChild("Shirt") local p = f:FindFirstChild("Pants") local s1 = script.Parent.Parent.Parent.Clothes.Shirt:clone() local p1 = script.Parent.Parent.Parent.Clothes.Pants:clone() s.Parent = script.Parent.Parent.PlayerStorage p.Parent = script.Parent.Parent.PlayerStorage wait() s1.Parent = f p1.Parent = f wait(5) s1:remove() p1:remove() s.Parent = f p.Parent = f end end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Error:
13:42:56.616 - Clothes is not a valid member of Model
Use :IsA()
. The shirt and pants are part of the Clothing class. :IsA()
checks to see if something is a certain class. For instance.
game.Workspace:IsA("Workspace") --true game.Workspace:IsA("Clothing") --false
if
statements check to see if something is true unless you tell it to check if it's false or not true.
if game.Workspace:IsA("Workspace") then print("Workspace is a workspace.") --This will only print end if game.Workspace:IsA("Clothing") then print("Workspace is a shirt or pants.") --Because this is false end
Now we mix it with your script so we get...
dist = 10 function onClicked() local players = game.Players:GetChildren() for i = 1, #players do if (players[i].Character.Torso.Position - script.Parent.Position).magnitude < dist then local name = players[i].Name local clothing = players[i]:GetChildren() for i = 1, #clothing do if clothing[i]:IsA("Clothing") then local f = game.Workspace:FindFirstChild(name) local s = f:FindFirstChild("Shirt") local p = f:FindFirstChild("Pants") local s1 = script.Parent.Parent.Parent.Clothes.Shirt:clone() local p1 = script.Parent.Parent.Parent.Clothes.Pants:clone() s.Parent = script.Parent.Parent.PlayerStorage p.Parent = script.Parent.Parent.PlayerStorage wait() s1.Parent = f p1.Parent = f wait(5) s1:remove() p1:remove() s.Parent = f p.Parent = f end end end end end script.Parent.ClickDetector.MouseClick:connect(onClicked)