01 | player = game.Players.LocalPlayer |
02 | h = player.Character |
03 | script.Parent.MouseButton 1 Down:connect( function () |
04 | h.face:Destroy() |
05 | wait( 0.01 ) |
06 | newface = Instance.new( "Decal" ,h) |
07 | newface.Head = "Front" |
08 | newface.Name = "face" |
09 | newface.Texture = "http://www.roblox.com/asset/?id=138224650" |
10 | end |
When I select on the gui the players face is not removed.
The problem is h
. Variable h is the character. Not the head that the face is it. You also need a )
after the end
. This is because the function is in the connect. This is a shorter way to write event scripts but you need the )
. So basicly you just need to close the parentheses. Here this is better:
01 | player = game.Players.LocalPlayer |
02 | h = player.Character.Head |
03 | script.Parent.MouseButton 1 Down:connect( function () |
04 | h.face:Destroy() |
05 | --No wait needed. |
06 | local newface = Instance.new( "Decal" ,h) |
07 | newface.Head = "Front" |
08 | newface.Name = "face" |
09 | newface.Texture = "http://www.roblox.com/asset/?id=138224650" |
10 | end ) --You need the ")" because of line 3. |
Hat:
01 | player = game.Players.LocalPlayer |
02 | h = player.Character.Head |
03 | script.Parent.MouseButton 1 Down:connect( function () |
04 | h.face:Destroy() |
05 | for _,v in pairs (player.Character:GetChildren()) do |
06 | if v.ClassName = = "Hat" then |
07 | v:Destroy() |
08 | game.ServerStorage.Hat:clone().Parent = player.Character --Put the hat in ServerStorage and name it "Hat". |
09 | end |
10 | end |
11 | local newface = Instance.new( "Decal" ,h) |
12 | newface.Name = "face" |
13 | newface.Texture = "http://www.roblox.com/asset/?id=138224650" |
14 | end ) |
EDIT:
For multiple hats and this is both of the scripts combined
01 | player = game.Players.LocalPlayer |
02 | h = player.Character.Head |
03 | script.Parent.MouseButton 1 Down:connect( function () |
04 | if not h.face.Texture = = "http://www.roblox.com/asset/?id=138224650" then |
05 | h.face:Destroy() |
06 | for _,v in pairs (player.Character:GetChildren()) do |
07 | if v.ClassName = = "Hat" then |
08 | v:Destroy() |
09 | for _,i in pairs (game.ServerStorage:GetChildren()) do |
10 | i:clone().Parent = player.Character |
11 | player.Character:MakeJoints() |
12 | end |
13 | end |
14 | end |
15 | local newface = Instance.new( "Decal" ,h) |
16 | newface.Name = "face" |
17 | newface.Texture = "http://www.roblox.com/asset/?id=138224650" |
18 | end |
19 | end ) |
Hats:
01 | p = game.Players.LocalPlayer |
02 | char = p.Character |
03 | Storage = game:GetService( "ServerStorage" ) --Using :GetService() because the script can cause an error if used in multiplayer(uploaded to roblox) when not calling the service |
04 |
05 | script.Parent.MouseButton 1 Down:connect( function () |
06 | local cont = char:GetChildren() |
07 | for i,v in pairs (cont) do -- Removing all other hats |
08 | if v:IsA( "Hat" ) then |
09 | v:Destroy() |
10 | end |
11 | end |
12 | local hat = Storage.HATNAME:clone() --Change HATNAME to the name of the hat and put the hat in ServerStorage |
13 | hat.Parent = char |
14 | hat.Name = "Hat" |
15 | --If the hat is not anchored in ServerStorage it should appear on your head. |
16 | end ) |