I am creating a neat little project that is very ambitious for a poor scripter like myself. I am writing code for a character customization prompt that allows for the use of hats to be placed upon the character's head (whom is using an R15 rig.) The hat places on just fine, however, when I click the button again and the script checks to see if the hair is on, the hair just stays on and doesn't get removed. Here's the block of code I used:
Character = game.Workspace.IntroSequence.Character MyCharacter = game.Players.LocalPlayer.Character x = game.Lighting["rickshair"]:clone() script.Parent.MouseButton1Down:connect(function() if MyCharacter:FindFirstChild("rickshair") ~= nil then Character["rickshair"]:destroy() MyCharacter["rickshair"]:destroy() x:clone() end if MyCharacter:FindFirstChild("rickshair")== nil then x.Parent = Character x.Parent = Character x.Parent = MyCharacter x.Parent = MyCharacter end end)
You may notice the "Character" and "MyCharacter" definitions. This is because in the character customization screen I use a different model than the actual player, but place accessories on both at the same time. Hopefully that concludes any confusion.
Character = game.Workspace.IntroSequence.Character MyCharacter = game.Players.LocalPlayer.Character x = game.Lighting["rickshair"]:Clone() script.Parent.MouseButton1Down:Connect(function() if MyCharacter:FindFirstChild("rickshair") ~= nil then Character["rickshair"]:Destroy() MyCharacter["rickshair"]:Destroy() x:clone() end if MyCharacter:FindFirstChild("rickshair")== nil then x.Parent = Character x.Parent = Character x.Parent = MyCharacter x.Parent = MyCharacter end end)