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 9 years ago
player = game.Players.LocalPlayer
h = player.Character
script.Parent.MouseButton1Down:connect(function()
h.face:Destroy()
wait(0.01)
newface = Instance.new("Decal",h)
newface.Head = "Front" 
newface.Name = "face"
newface.Texture = "http://www.roblox.com/asset/?id=138224650"
end

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

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

2 answers

Log in to vote
2
Answered by 9 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:

player = game.Players.LocalPlayer
h = player.Character.Head
script.Parent.MouseButton1Down:connect(function()
h.face:Destroy()
--No wait needed.
local newface = Instance.new("Decal",h)
newface.Head = "Front" 
newface.Name = "face"
newface.Texture = "http://www.roblox.com/asset/?id=138224650"
end) --You need the ")" because of line 3.

Hat:

player = game.Players.LocalPlayer
h = player.Character.Head
script.Parent.MouseButton1Down:connect(function()
    h.face:Destroy()
    for _,v in pairs(player.Character:GetChildren()) do
        if v.ClassName == "Hat" then
            v:Destroy()
            game.ServerStorage.Hat:clone().Parent = player.Character --Put the hat in ServerStorage and name it "Hat".
        end
    end
    local newface = Instance.new("Decal",h)
    newface.Name = "face"
    newface.Texture = "http://www.roblox.com/asset/?id=138224650"
end)

EDIT:

For multiple hats and this is both of the scripts combined

player = game.Players.LocalPlayer
h = player.Character.Head
script.Parent.MouseButton1Down:connect(function()
    if not h.face.Texture == "http://www.roblox.com/asset/?id=138224650" then
    h.face:Destroy()
    for _,v in pairs(player.Character:GetChildren()) do
        if v.ClassName == "Hat" then
            v:Destroy()
            for _,i in pairs(game.ServerStorage:GetChildren()) do
            i:clone().Parent = player.Character
            player.Character:MakeJoints()
            end
        end
    end
    local newface = Instance.new("Decal",h)
    newface.Name = "face"
    newface.Texture = "http://www.roblox.com/asset/?id=138224650"
    end
end)
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 — 9y
0
I am having an error the face is removed but the new one is not shown. Relampago1204 73 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

Hats:

p = game.Players.LocalPlayer
char = p.Character
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

script.Parent.MouseButton1Down:connect(function()
    local cont = char:GetChildren()
    for i,v in pairs(cont) do -- Removing all other hats
        if v:IsA("Hat") then
            v:Destroy()
        end
    end
    local hat = Storage.HATNAME:clone() --Change HATNAME to the name of the hat and put the hat in ServerStorage
    hat.Parent = char
    hat.Name = "Hat"
    --If the hat is not anchored in ServerStorage it should appear on your head.
end)

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 — 9y

Answer this question