Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this script that is placed in a GUI remove the players face and replace it when clicked?

Asked by 10 years ago
01player = game.Players.LocalPlayer
02h = player.Character
03script.Parent.MouseButton1Down:connect(function()
04h.face:Destroy()
05wait(0.01)
06newface = Instance.new("Decal",h)
07newface.Head = "Front"
08newface.Name = "face"
10end

When I select on the gui the players face is not removed.

0
Is this a Script or a LocalScript? BlueTaslem 18071 — 10y
0
A local script. Relampago1204 73 — 10y
0
Hello? Relampago1204 73 — 10y
0
Why ask if you won't do anything. Relampago1204 73 — 10y

2 answers

Log in to vote
2
Answered by 10 years ago

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:

01player = game.Players.LocalPlayer
02h = player.Character.Head
03script.Parent.MouseButton1Down:connect(function()
04h.face:Destroy()
05--No wait needed.
06local newface = Instance.new("Decal",h)
07newface.Head = "Front"
08newface.Name = "face"
10end) --You need the ")" because of line 3.

Hat:

01player = game.Players.LocalPlayer
02h = player.Character.Head
03script.Parent.MouseButton1Down: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"
14end)

EDIT:

For multiple hats and this is both of the scripts combined

01player = game.Players.LocalPlayer
02h = player.Character.Head
03script.Parent.MouseButton1Down: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
19end)
0
Excuse me. I need more help. I want a player to get a certain Hat when they click on the Gui. I was afraid to ask because I don't know how to script that. How would I do that? Relampago1204 73 — 10y
0
I am having an error the face is removed but the new one is not shown. Relampago1204 73 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

Hats:

01p = game.Players.LocalPlayer
02char = p.Character
03Storage = 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 
05script.Parent.MouseButton1Down: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.
16end)
0
Does :IsA("Hat") work? This doesn't do multiple hats, and the hats don't stick. Use :MakeJoints() on the character to make it stick. EzraNehemiah_TF2 3552 — 10y

Answer this question